diff --git a/src/kff.App.js b/src/kff.App.js index e80d4ee..451f393 100644 --- a/src/kff.App.js +++ b/src/kff.App.js @@ -51,6 +51,15 @@ kff.App = kff.createClass( } }; + if(this.options.dispatcher) + { + config.services['kff.Dispatcher'] = { + args: [this.options.dispatcher.actions || {}] + }; + + config.services['kff.FrontController'].args[0].dispatcher = '@kff.Dispatcher'; + } + this.serviceContainer = new kff.ServiceContainer(config, require); if('parameters' in options) this.serviceContainer.registerParameters(options.parameters, true); if('services' in options) this.serviceContainer.registerServices(options.services, true); @@ -85,15 +94,6 @@ kff.App = kff.createClass( { frontController.setStateHandler(this.serviceContainer.resolveParameters(this.options.stateHandler)); } - if(this.options.dispatcher) - { - var dispatcher = this.serviceContainer.resolveParameters(this.options.dispatcher); - if(dispatcher && typeof dispatcher.registerActions === 'function') - { - if(this.options.actions) dispatcher.registerActions(this.options.actions); - frontController.setDispatcher(dispatcher); - } - } if(this.options.defaultView) { frontController.setDefaultView(this.options.defaultView); diff --git a/src/kff.Dispatcher.js b/src/kff.Dispatcher.js index b31f872..441e826 100644 --- a/src/kff.Dispatcher.js +++ b/src/kff.Dispatcher.js @@ -11,6 +11,9 @@ kff.Dispatcher = kff.createClass({ createCallback: function(fn) { var dispatcher = this; + if(typeof fn !== 'function') { + throw new Error('Dispatcher action is not a function'); + } if(fn.length <= 1) { return function(event)