javascript - Backbone router events - always two events per route? -
i using newer backbone event listening mechanism. in router initialize method, looks this:
this.listento(this,'all',function(route,action){ console.log('router invoked, route:',route,'action:',action); });
in debugger, when put breakpoint on console.log statement, unsuspected.
for each new route, combination
route action route:x null route x
so in real life looks like:
route action route:home null route home route:index null route index
so question - why there 2 separate events being fired each route, , why differ above?
here proof:
because router.route
fires 2 separate events per route
operation:
route: function(route, name, callback) { if (!_.isregexp(route)) route = this._routetoregexp(route); if (_.isfunction(name)) { callback = name; name = ''; } if (!callback) callback = this[name]; var router = this; backbone.history.route(route, function(fragment) { var args = router._extractparameters(route, fragment); if (router.execute(callback, args, name) !== false) { router.trigger.apply(router, ['route:' + name].concat(args)); router.trigger('route', name, args); backbone.history.trigger('route', router, name, args); } }); return this; },
http://documentcloud.github.io/backbone/docs/backbone.html#section-152
the first 1 calls actual trigger router, ['route:' + name].concat(args)
, second 1 first route
event.
Comments
Post a Comment