Skip to content

Commit

Permalink
refactor(kff.App): dispatcher config should be compatible with servic…
Browse files Browse the repository at this point in the history
…e container config
  • Loading branch information
karfcz committed Jan 11, 2015
1 parent dfe5152 commit 9b66ec1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/kff.App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/kff.Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9b66ec1

Please sign in to comment.