Skip to content

Commit

Permalink
Allow handles to be inherited properly.
Browse files Browse the repository at this point in the history
So now you can set handles on e.g. the router and a single controller and it'll wait on _both_ of them.
  • Loading branch information
tmeasday committed Sep 13, 2013
1 parent 3e0e22f commit 4129706
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/client/route_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ _.extend(RouteController.prototype, {
this['data'] = getOption('data');
this['template'] = getOption('template') || (this.route && this.route.name);
this['renderTemplates'] = getOption('renderTemplates');
this['waitOn'] = getOption('waitOn');
this['waitOn'] = []
.concat(RouterUtils.toArray(routerOptions.waitOn))
.concat(RouterUtils.toArray(routeOptions.waitOn))
.concat(RouterUtils.toArray(options.waitOn))
.concat(RouterUtils.toArray(this.waitOn));
},

/**
Expand Down Expand Up @@ -245,16 +249,18 @@ _.extend(RouteController.prototype, {
return onReady.call(this);

if (_.isFunction(handles)) {
handles = handles.call(self);
if (!handles)
throw new Error(
'It looks like your waitOn function is not returning anything!');
}

if (!_.isArray(handles))
handles = [handles];

_.each(handles, function (handle) {

// each handle could potentially be a function that returns handles, check
handles = _.map(handles, function(handle) {
return (_.isFunction(handle)) ? handle.call(self) : handle;
});

if (!handles)
throw new Error(
'It looks like your waitOn function is not returning anything!');

_.each(_.flatten(handles), function (handle) {
if (!handle.ready())
isReady = false;
});
Expand Down

0 comments on commit 4129706

Please sign in to comment.