From a99494ab4cefef134608502e69ed4b0ed40643a9 Mon Sep 17 00:00:00 2001 From: Paul Falgout Date: Sat, 23 Jan 2016 22:52:10 -0600 Subject: [PATCH] bump and build v0.2.0 --- CHANGELOG.md | 9 ++++++++- dist/backbone.eventrouter.js | 7 ++++--- dist/backbone.eventrouter.js.map | 2 +- dist/backbone.eventrouter.min.js | 4 ++-- dist/backbone.eventrouter.min.js.map | 4 ++-- package.json | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6594ab8..38d3955 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ +#### v0.2.0 + +* Test Coverage 100% +* **BREAKING:** Moved `translateRoute` to a static method on `Backbone.EventRouter` +* Fixed the arguments passed to `noMatch` event +* Fixed the event name being passed on navigate (Thanks **@Courey**!) + #### v0.1.1 -* Renamed `addTriggerRoute` to `addRouteTrigger` +* **BREAKING:** Renamed `addTriggerRoute` to `addRouteTrigger` * Update to Node v4 #### v0.1.0 diff --git a/dist/backbone.eventrouter.js b/dist/backbone.eventrouter.js index 78737e5..49d58e4 100644 --- a/dist/backbone.eventrouter.js +++ b/dist/backbone.eventrouter.js @@ -1,6 +1,6 @@ /** * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel - * @version v0.1.1 + * @version v0.2.0 * @link https://github.com/RoundingWellOS/backbone.eventrouter * @license MIT */ @@ -217,7 +217,8 @@ // if no matching route exists do nothing if (!route) { - this.trigger.apply(this, ['noMatch'].concat(arguments)); + var args = _.drop(arguments, 0); + this.trigger.apply(this, ['noMatch'].concat(args)); return this; } @@ -225,7 +226,7 @@ return this; } - var eventArgs = _.drop(arguments, 0); + var eventArgs = _.drop(arguments, 1); var translatedRoute = this.translateRoute(route, eventArgs); diff --git a/dist/backbone.eventrouter.js.map b/dist/backbone.eventrouter.js.map index 3465f10..0fc4c6b 100644 --- a/dist/backbone.eventrouter.js.map +++ b/dist/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AAC,CAAC,GAAG,MAAM,CAAC;KAC/C;;;;;;;;;;;;AAYD,iBAAa,EAAE,uBAAS,KAAK,EAAE,GAAG,EAAC;;AAEjC,UAAI,UAAU,GAAG,aAAa,CAAC;;AAE/B,aAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;KACvC;;;;;;;;;;;;;AAaD,kBAAc,EAAE,wBAAS,KAAK,EAAE,SAAS,EAAE;AACzC,aAAO,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;KACvD;GACF,CAAC,CAAC;;AAEH,MAAI,oBAAoB,GAAG,WAAW,CAAC;;AAEvC,SAAO,oBAAoB,CAAC;CAE7B,CAAC,CAAE","file":"backbone.eventrouter.js","sourcesContent":["/**\n * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel\n * @version v0.1.1\n * @link https://github.com/RoundingWellOS/backbone.eventrouter\n * @license MIT\n */\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone'), require('backbone.radio')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone', 'backbone.radio'], factory) :\n global.Backbone.EventRouter = factory(global._, global.Backbone, global.Radio)\n}(this, function (_, Backbone, Radio) { 'use strict';\n\n var EventRouter = Backbone.EventRouter = Backbone.Router.extend({\n\n /**\n * @public\n * @constructs EventRouter\n * @param {Object} [options] - Settings for the EventRouter\n * @param {Boolean} [options.channelName]\n * @param {Boolean} [options.routeTriggers]\n */\n constructor: function(options) {\n options = _.extend({}, options);\n\n // Backbone.Router routes are added first\n // Routes can be added after the triggerRoutes with the Backbone.Router API\n Backbone.Router.apply(this, arguments);\n\n _.extend(this, _.pick(options, ['channelName', 'routeTriggers']));\n\n this._ch = Backbone.Radio.channel(_.result(this, 'channelName'));\n\n this._initRoutes();\n\n this.listenTo(this._ch, 'all', this.navigateFromEvent);\n },\n\n /**\n * The Radio Channel name.\n *\n * @type {String}\n * @default 'event-router'\n */\n channelName: 'event-router',\n\n /**\n * Get the router's Radio channel instance\n *\n * @public\n * @method getChannel\n * @memberOf EventRouter\n * @returns {Backbone.Radio.Channel}\n */\n getChannel: function() {\n return this._ch;\n },\n\n /**\n * For each routeTrigger it adds a route to Backbone.Router\n *\n * @private\n * @method _initRoutes\n * @memberOf EventRouter\n */\n _initRoutes: function() {\n this._routeTriggers = _.result(this, 'routeTriggers') || {};\n\n _.each(this._routeTriggers, this._addRouteTrigger, this);\n },\n\n /**\n * Adds a route(s) to Backbone.Router which on route triggers\n * the appropriate event\n *\n * @private\n * @method _addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n */\n _addRouteTrigger: function(routes, event){\n // handle any route as an array by default for the _.each\n routes = _.isArray(routes) ? routes : [routes];\n\n _.each(routes, function(route) {\n this.route(route, event, _.bind(this._ch.trigger, this._ch, event));\n }, this);\n },\n\n /**\n * Adds a routeTrigger, and route(s) to Backbone.Router\n * which on route triggers the appropriate event.\n *\n * @public\n * @method addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n addRouteTrigger: function(routes, event){\n this._routeTriggers[event] = routes;\n this._addRouteTrigger(routes, event);\n\n return this;\n },\n\n /**\n * Overrides `Backbone.Router.route()\n * Like Backbone.Router.Route but with before events\n * It also temporarily stores the event for understanding\n * what route is currently being handled.\n *\n * @public\n * @method route\n * @param {String} route - Route string\n * @param {String} [name] - Name of route\n * @param {String} callback - Function called on route\n * @event EventRouter#before:route - passes route name and route arguments\n * @event EventRouter#before:route:{event_name} - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n route: function(route, name, callback) {\n if (_.isFunction(name)) {\n callback = name;\n name = '';\n }\n if (!callback) {\n callback = this[name];\n }\n\n var wrappedCallback = _.bind(function() {\n\n var args = _.drop(arguments, 0);\n\n //trigger before: events that match currently triggered events\n this.trigger('before:route', name, args);\n this.trigger.apply(this, ['before:route:' + name].concat(args));\n\n this._storeRouteTrigger([name].concat(args));\n callback.apply(this, args);\n this._clearRouteTrigger();\n\n }, this);\n\n return Backbone.Router.prototype.route.call(this, route, name, wrappedCallback);\n },\n\n /**\n * Stores the route name and route arguments on a stack\n *\n * @private\n * @method _storeRouteTrigger\n * @param {Array} args - Array of route name and route arguments\n * @memberOf EventRouter\n */\n _storeRouteTrigger: function(args){\n this._routeArgs = this._routeArgs || [];\n this._routeArgs.push(args);\n },\n\n\n /**\n * Gets the top of the triggered route store stack\n *\n * @private\n * @method _getCurrentRouteTrigger\n * @memberOf EventRouter\n * @returns {Array}\n */\n _getCurrentRouteTrigger: function(){\n return _.last(this._routeArgs) || [];\n },\n\n /**\n * Pops the latests route triggered off of the store stack\n *\n * @private\n * @method _clearRouteTrigger\n * @memberOf EventRouter\n */\n _clearRouteTrigger: function(){\n this._routeArgs.pop();\n },\n\n /**\n * Checks to see if the current event being tests is the latest\n * route being handled by comparing the route name and arguments\n *\n * @private\n * @method _isTriggeredFromRoute\n * @memberOf EventRouter\n * @returns {Boolean}\n */\n _isTriggeredFromRoute: function(){\n var currentRoute = this._getCurrentRouteTrigger();\n\n if(arguments.length !== currentRoute.length){\n return false;\n }\n\n return (arguments.length === _.union(arguments, this.currentRoute).length);\n },\n\n /**\n * Takes a event string and any arguments passed to that event\n * And if not initiated by a route, translates the event into a\n * URL and navigates to it without re-triggering the route\n *\n * @public\n * @method navigateFromEvent\n * @param {String} event - Event string\n * @event EventRouter#noMatch - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n navigateFromEvent: function(event) {\n var route = this.getDefaultRoute(event);\n\n // if no matching route exists do nothing\n if(!route) {\n this.trigger.apply(this, ['noMatch'].concat(arguments));\n return this;\n }\n\n if(this._isTriggeredFromRoute.apply(this, arguments)) {\n return this;\n }\n\n var eventArgs = _.drop(arguments, 0);\n\n var translatedRoute = this.translateRoute(route, eventArgs);\n\n // update URL without triggering the route\n return this.navigate(translatedRoute, { trigger: false });\n },\n\n /**\n * Get the default route string\n * Either the first of the array or the passed in event if singular\n *\n * @public\n * @method getDefaultRoute\n * @memberOf EventRouter\n * @returns {String}\n */\n getDefaultRoute: function(event) {\n var routes = this._routeTriggers[event];\n\n return _.isArray(routes) ? routes[0] : routes;\n },\n\n /**\n * Finds the next name params (ie: :param) and replaces it with the arg\n *\n * @private\n * @method _replaceParam\n * @param {String} route - Route string\n * @param {String|Number} arg - value to replace named param\n * @memberOf EventRouter\n * @returns {String}\n */\n _replaceParam: function(route, arg){\n // https://github.com/jashkenas/backbone/blob/1.2.1/backbone.js#L1425\n var namedParam = /(\\(\\?)?:\\w+/;\n\n return route.replace(namedParam, arg);\n },\n\n /**\n * Takes a route string and an array or arguments\n * and returns a url with the named params replaced with the argument values\n *\n * @public\n * @method translateRoute\n * @param {String} route - Route string\n * @param {Array} eventArgs - Passed event arguments\n * @memberOf EventRouter\n * @returns {String}\n */\n translateRoute: function(route, eventArgs) {\n return _.reduce(eventArgs, this._replaceParam, route);\n }\n });\n\n var backbone_eventrouter = EventRouter;\n\n return backbone_eventrouter;\n\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["backbone.eventrouter.js"],"names":[],"mappings":";;;;;;AAMA,AAAC,CAAA,UAAU,MAAM,EAAE,OAAO,EAAE;AAC1B,SAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAC9J,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,YAAY,EAAE,UAAU,EAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC,GA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CAAC;;AAEH,MAAI,oBAAoB,GAAG,WAAW,CAAC;;AAEvC,SAAO,oBAAoB,CAAC;CAE7B,CAAC,CAAE","file":"backbone.eventrouter.js","sourcesContent":["/**\n * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel\n * @version v0.2.0\n * @link https://github.com/RoundingWellOS/backbone.eventrouter\n * @license MIT\n */\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone'), require('backbone.radio')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone', 'backbone.radio'], factory) :\n global.Backbone.EventRouter = factory(global._, global.Backbone, global.Radio)\n}(this, function (_, Backbone, Radio) { 'use strict';\n\n var EventRouter = Backbone.EventRouter = Backbone.Router.extend({\n\n /**\n * @public\n * @constructs EventRouter\n * @param {Object} [options] - Settings for the EventRouter\n * @param {Boolean} [options.channelName]\n * @param {Boolean} [options.routeTriggers]\n */\n constructor: function(options) {\n options = _.extend({}, options);\n\n // Backbone.Router routes are added first\n // Routes can be added after the triggerRoutes with the Backbone.Router API\n Backbone.Router.apply(this, arguments);\n\n _.extend(this, _.pick(options, ['channelName', 'routeTriggers']));\n\n this._ch = Backbone.Radio.channel(_.result(this, 'channelName'));\n\n this._initRoutes();\n\n this.listenTo(this._ch, 'all', this.navigateFromEvent);\n },\n\n /**\n * The Radio Channel name.\n *\n * @type {String}\n * @default 'event-router'\n */\n channelName: 'event-router',\n\n /**\n * Get the router's Radio channel instance\n *\n * @public\n * @method getChannel\n * @memberOf EventRouter\n * @returns {Backbone.Radio.Channel}\n */\n getChannel: function() {\n return this._ch;\n },\n\n /**\n * For each routeTrigger it adds a route to Backbone.Router\n *\n * @private\n * @method _initRoutes\n * @memberOf EventRouter\n */\n _initRoutes: function() {\n this._routeTriggers = _.result(this, 'routeTriggers') || {};\n\n _.each(this._routeTriggers, this._addRouteTrigger, this);\n },\n\n /**\n * Adds a route(s) to Backbone.Router which on route triggers\n * the appropriate event\n *\n * @private\n * @method _addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n */\n _addRouteTrigger: function(routes, event){\n // handle any route as an array by default for the _.each\n routes = _.isArray(routes) ? routes : [routes];\n\n _.each(routes, function(route) {\n this.route(route, event, _.bind(this._ch.trigger, this._ch, event));\n }, this);\n },\n\n /**\n * Adds a routeTrigger, and route(s) to Backbone.Router\n * which on route triggers the appropriate event.\n *\n * @public\n * @method addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n addRouteTrigger: function(routes, event){\n this._routeTriggers[event] = routes;\n this._addRouteTrigger(routes, event);\n\n return this;\n },\n\n /**\n * Overrides `Backbone.Router.route()\n * Like Backbone.Router.Route but with before events\n * It also temporarily stores the event for understanding\n * what route is currently being handled.\n *\n * @public\n * @method route\n * @param {String} route - Route string\n * @param {String} [name] - Name of route\n * @param {String} callback - Function called on route\n * @event EventRouter#before:route - passes route name and route arguments\n * @event EventRouter#before:route:{event_name} - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n route: function(route, name, callback) {\n if (_.isFunction(name)) {\n callback = name;\n name = '';\n }\n if (!callback) {\n callback = this[name];\n }\n\n var wrappedCallback = _.bind(function() {\n\n var args = _.drop(arguments, 0);\n\n //trigger before: events that match currently triggered events\n this.trigger('before:route', name, args);\n this.trigger.apply(this, ['before:route:' + name].concat(args));\n\n this._storeRouteTrigger([name].concat(args));\n callback.apply(this, args);\n this._clearRouteTrigger();\n\n }, this);\n\n return Backbone.Router.prototype.route.call(this, route, name, wrappedCallback);\n },\n\n /**\n * Stores the route name and route arguments on a stack\n *\n * @private\n * @method _storeRouteTrigger\n * @param {Array} args - Array of route name and route arguments\n * @memberOf EventRouter\n */\n _storeRouteTrigger: function(args){\n this._routeArgs = this._routeArgs || [];\n this._routeArgs.push(args);\n },\n\n\n /**\n * Gets the top of the triggered route store stack\n *\n * @private\n * @method _getCurrentRouteTrigger\n * @memberOf EventRouter\n * @returns {Array}\n */\n _getCurrentRouteTrigger: function(){\n return _.last(this._routeArgs) || [];\n },\n\n /**\n * Pops the latests route triggered off of the store stack\n *\n * @private\n * @method _clearRouteTrigger\n * @memberOf EventRouter\n */\n _clearRouteTrigger: function(){\n this._routeArgs.pop();\n },\n\n /**\n * Checks to see if the current event being tests is the latest\n * route being handled by comparing the route name and arguments\n *\n * @private\n * @method _isTriggeredFromRoute\n * @memberOf EventRouter\n * @returns {Boolean}\n */\n _isTriggeredFromRoute: function(){\n var currentRoute = this._getCurrentRouteTrigger();\n\n if(arguments.length !== currentRoute.length){\n return false;\n }\n\n return (arguments.length === _.union(arguments, this.currentRoute).length);\n },\n\n /**\n * Takes a event string and any arguments passed to that event\n * And if not initiated by a route, translates the event into a\n * URL and navigates to it without re-triggering the route\n *\n * @public\n * @method navigateFromEvent\n * @param {String} event - Event string\n * @event EventRouter#noMatch - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n navigateFromEvent: function(event) {\n var route = this.getDefaultRoute(event);\n\n // if no matching route exists do nothing\n if(!route) {\n var args = _.drop(arguments, 0);\n this.trigger.apply(this, ['noMatch'].concat(args));\n return this;\n }\n\n if(this._isTriggeredFromRoute.apply(this, arguments)) {\n return this;\n }\n\n var eventArgs = _.drop(arguments, 1);\n\n var translatedRoute = this.translateRoute(route, eventArgs);\n\n // update URL without triggering the route\n return this.navigate(translatedRoute, { trigger: false });\n },\n\n /**\n * Get the default route string\n * Either the first of the array or the passed in event if singular\n *\n * @public\n * @method getDefaultRoute\n * @memberOf EventRouter\n * @returns {String}\n */\n getDefaultRoute: function(event) {\n var routes = this._routeTriggers[event];\n\n return _.isArray(routes) ? routes[0] : routes;\n },\n\n /**\n * Finds the next name params (ie: :param) and replaces it with the arg\n *\n * @private\n * @method _replaceParam\n * @param {String} route - Route string\n * @param {String|Number} arg - value to replace named param\n * @memberOf EventRouter\n * @returns {String}\n */\n _replaceParam: function(route, arg){\n // https://github.com/jashkenas/backbone/blob/1.2.1/backbone.js#L1425\n var namedParam = /(\\(\\?)?:\\w+/;\n\n return route.replace(namedParam, arg);\n },\n\n /**\n * Takes a route string and an array or arguments\n * and returns a url with the named params replaced with the argument values\n *\n * @public\n * @method translateRoute\n * @param {String} route - Route string\n * @param {Array} eventArgs - Passed event arguments\n * @memberOf EventRouter\n * @returns {String}\n */\n translateRoute: function(route, eventArgs) {\n return _.reduce(eventArgs, this._replaceParam, route);\n }\n });\n\n var backbone_eventrouter = EventRouter;\n\n return backbone_eventrouter;\n\n}));\n//# sourceMappingURL=./backbone.eventrouter.js.map"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/backbone.eventrouter.min.js b/dist/backbone.eventrouter.min.js index 4ccb704..01d5a8e 100644 --- a/dist/backbone.eventrouter.min.js +++ b/dist/backbone.eventrouter.min.js @@ -1,8 +1,8 @@ /** * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel - * @version v0.1.1 + * @version v0.2.0 * @link https://github.com/RoundingWellOS/backbone.eventrouter * @license MIT */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("underscore"),require("backbone"),require("backbone.radio")):"function"==typeof define&&define.amd?define(["underscore","backbone","backbone.radio"],e):t.Backbone.EventRouter=e(t._,t.Backbone,t.Radio)}(this,function(t,e,r){"use strict";var i=e.EventRouter=e.Router.extend({constructor:function(r){r=t.extend({},r),e.Router.apply(this,arguments),t.extend(this,t.pick(r,["channelName","routeTriggers"])),this._ch=e.Radio.channel(t.result(this,"channelName")),this._initRoutes(),this.listenTo(this._ch,"all",this.navigateFromEvent)},channelName:"event-router",getChannel:function(){return this._ch},_initRoutes:function(){this._routeTriggers=t.result(this,"routeTriggers")||{},t.each(this._routeTriggers,this._addRouteTrigger,this)},_addRouteTrigger:function(e,r){e=t.isArray(e)?e:[e],t.each(e,function(e){this.route(e,r,t.bind(this._ch.trigger,this._ch,r))},this)},addRouteTrigger:function(t,e){return this._routeTriggers[e]=t,this._addRouteTrigger(t,e),this},route:function(r,i,n){t.isFunction(i)&&(n=i,i=""),n||(n=this[i]);var o=t.bind(function(){var e=t.drop(arguments,0);this.trigger("before:route",i,e),this.trigger.apply(this,["before:route:"+i].concat(e)),this._storeRouteTrigger([i].concat(e)),n.apply(this,e),this._clearRouteTrigger()},this);return e.Router.prototype.route.call(this,r,i,o)},_storeRouteTrigger:function(t){this._routeArgs=this._routeArgs||[],this._routeArgs.push(t)},_getCurrentRouteTrigger:function(){return t.last(this._routeArgs)||[]},_clearRouteTrigger:function(){this._routeArgs.pop()},_isTriggeredFromRoute:function(){var e=this._getCurrentRouteTrigger();return arguments.length!==e.length?!1:arguments.length===t.union(arguments,this.currentRoute).length},navigateFromEvent:function(e){var r=this.getDefaultRoute(e);if(!r)return this.trigger.apply(this,["noMatch"].concat(arguments)),this;if(this._isTriggeredFromRoute.apply(this,arguments))return this;var i=t.drop(arguments,0),n=this.translateRoute(r,i);return this.navigate(n,{trigger:!1})},getDefaultRoute:function(e){var r=this._routeTriggers[e];return t.isArray(r)?r[0]:r},_replaceParam:function(t,e){var r=/(\(\?)?:\w+/;return t.replace(r,e)},translateRoute:function(e,r){return t.reduce(r,this._replaceParam,e)}}),n=i;return n}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("underscore"),require("backbone"),require("backbone.radio")):"function"==typeof define&&define.amd?define(["underscore","backbone","backbone.radio"],e):t.Backbone.EventRouter=e(t._,t.Backbone,t.Radio)}(this,function(t,e,r){"use strict";var i=e.EventRouter=e.Router.extend({constructor:function(r){r=t.extend({},r),e.Router.apply(this,arguments),t.extend(this,t.pick(r,["channelName","routeTriggers"])),this._ch=e.Radio.channel(t.result(this,"channelName")),this._initRoutes(),this.listenTo(this._ch,"all",this.navigateFromEvent)},channelName:"event-router",getChannel:function(){return this._ch},_initRoutes:function(){this._routeTriggers=t.result(this,"routeTriggers")||{},t.each(this._routeTriggers,this._addRouteTrigger,this)},_addRouteTrigger:function(e,r){e=t.isArray(e)?e:[e],t.each(e,function(e){this.route(e,r,t.bind(this._ch.trigger,this._ch,r))},this)},addRouteTrigger:function(t,e){return this._routeTriggers[e]=t,this._addRouteTrigger(t,e),this},route:function(r,i,n){t.isFunction(i)&&(n=i,i=""),n||(n=this[i]);var o=t.bind(function(){var e=t.drop(arguments,0);this.trigger("before:route",i,e),this.trigger.apply(this,["before:route:"+i].concat(e)),this._storeRouteTrigger([i].concat(e)),n.apply(this,e),this._clearRouteTrigger()},this);return e.Router.prototype.route.call(this,r,i,o)},_storeRouteTrigger:function(t){this._routeArgs=this._routeArgs||[],this._routeArgs.push(t)},_getCurrentRouteTrigger:function(){return t.last(this._routeArgs)||[]},_clearRouteTrigger:function(){this._routeArgs.pop()},_isTriggeredFromRoute:function(){var e=this._getCurrentRouteTrigger();return arguments.length!==e.length?!1:arguments.length===t.union(arguments,this.currentRoute).length},navigateFromEvent:function(e){var r=this.getDefaultRoute(e);if(!r){var i=t.drop(arguments,0);return this.trigger.apply(this,["noMatch"].concat(i)),this}if(this._isTriggeredFromRoute.apply(this,arguments))return this;var n=t.drop(arguments,1),o=this.translateRoute(r,n);return this.navigate(o,{trigger:!1})},getDefaultRoute:function(e){var r=this._routeTriggers[e];return t.isArray(r)?r[0]:r},_replaceParam:function(t,e){var r=/(\(\?)?:\w+/;return t.replace(r,e)},translateRoute:function(e,r){return t.reduce(r,this._replaceParam,e)}}),n=i;return n}); //# sourceMappingURL=backbone.eventrouter.min.js.map diff --git a/dist/backbone.eventrouter.min.js.map b/dist/backbone.eventrouter.min.js.map index 11f887a..805a2d7 100644 --- a/dist/backbone.eventrouter.min.js.map +++ b/dist/backbone.eventrouter.min.js.map @@ -1,7 +1,7 @@ /** * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel - * @version v0.1.1 + * @version v0.2.0 * @link https://github.com/RoundingWellOS/backbone.eventrouter * @license MIT */ -{"version":3,"sources":["/source/backbone.eventrouter.js"],"names":["global","factory","exports","module","require","define","amd","Backbone","EventRouter","_","Radio","this","Router","extend","constructor","options","apply","arguments","pick","_ch","channel","result","_initRoutes","listenTo","navigateFromEvent","channelName","getChannel","_routeTriggers","each","_addRouteTrigger","routes","event","isArray","route","bind","trigger","addRouteTrigger","_route","name","callback","isFunction","wrappedCallback","args","drop","concat","_storeRouteTrigger","_clearRouteTrigger","prototype","call","_routeArgs","push","_getCurrentRouteTrigger","last","pop","_isTriggeredFromRoute","currentRoute","length","union","getDefaultRoute","eventArgs","translatedRoute","translateRoute","navigate","_replaceParam","arg","namedParam","replace","reduce","backbone_eventrouter"],"mappings":"CAMA,SAAWA,EAAQC,GACE,gBAAZC,UAA0C,mBAAXC,QAAyBA,OAAOD,QAAUD,EAAQG,QAAQ,cAAeA,QAAQ,YAAaA,QAAQ,mBAC1H,kBAAXC,SAAyBA,OAAOC,IAAMD,QAAQ,aAAc,WAAY,kBAAmBJ,GAClGD,EAAOO,SAASC,YAAcP,EAAQD,EAAOS,EAAGT,EAAOO,SAAUP,EAAOU,QACxEC,KAAM,SAAUF,EAAGF,EAAUG,GAAS,YAEtC,IAAIF,GAAcD,EAASC,YAAcD,EAASK,OAAOC,QASvDC,YAAa,SAASC,GACpBA,EAAUN,EAAEI,UAAWE,GAIvBR,EAASK,OAAOI,MAAML,KAAMM,WAE5BR,EAAEI,OAAOF,KAAMF,EAAES,KAAKH,GAAU,cAAe,mBAE/CJ,KAAKQ,IAAMZ,EAASG,MAAMU,QAAQX,EAAEY,OAAOV,KAAM,gBAEjDA,KAAKW,cAELX,KAAKY,SAASZ,KAAKQ,IAAK,MAAOR,KAAKa,oBAStCC,YAAa,eAUbC,WAAY,WACV,MAAOf,MAAKQ,KAUdG,YAAa,WACXX,KAAKgB,eAAiBlB,EAAEY,OAAOV,KAAM,qBAErCF,EAAEmB,KAAKjB,KAAKgB,eAAgBhB,KAAKkB,iBAAkB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,EAEF,MADAtB,MAAKwB,QAAQnB,MAAML,MAAO,WAAWiC,OAAO3B,YACrCN,IAGT,IAAGA,KAAK2C,sBAAsBtC,MAAML,KAAMM,WACxC,MAAON,KAGT,IAAIgD,GAAYlD,EAAEkC,KAAK1B,UAAW,GAE9B2C,EAAkBjD,KAAKkD,eAAe5B,EAAO0B,EAGjD,OAAOhD,MAAKmD,SAASF,GAAmBzB,SAAS,KAYnDuB,gBAAiB,SAAS3B,GACxB,GAAID,GAASnB,KAAKgB,eAAeI,EAEjC,OAAOtB,GAAEuB,QAAQF,GAAUA,EAAO,GAAKA,GAazCiC,cAAe,SAAS9B,EAAO+B,GAE7B,GAAIC,GAAa,aAEjB,OAAOhC,GAAMiC,QAAQD,EAAYD,IAcnCH,eAAgB,SAAS5B,EAAO0B,GAC9B,MAAOlD,GAAE0D,OAAOR,EAAWhD,KAAKoD,cAAe9B,MAI/CmC,EAAuB5D,CAE3B,OAAO4D","file":"backbone.eventrouter.min.js","sourcesContent":["/**\n * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel\n * @version v0.1.1\n * @link https://github.com/RoundingWellOS/backbone.eventrouter\n * @license MIT\n */\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone'), require('backbone.radio')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone', 'backbone.radio'], factory) :\n global.Backbone.EventRouter = factory(global._, global.Backbone, global.Radio)\n}(this, function (_, Backbone, Radio) { 'use strict';\n\n var EventRouter = Backbone.EventRouter = Backbone.Router.extend({\n\n /**\n * @public\n * @constructs EventRouter\n * @param {Object} [options] - Settings for the EventRouter\n * @param {Boolean} [options.channelName]\n * @param {Boolean} [options.routeTriggers]\n */\n constructor: function(options) {\n options = _.extend({}, options);\n\n // Backbone.Router routes are added first\n // Routes can be added after the triggerRoutes with the Backbone.Router API\n Backbone.Router.apply(this, arguments);\n\n _.extend(this, _.pick(options, ['channelName', 'routeTriggers']));\n\n this._ch = Backbone.Radio.channel(_.result(this, 'channelName'));\n\n this._initRoutes();\n\n this.listenTo(this._ch, 'all', this.navigateFromEvent);\n },\n\n /**\n * The Radio Channel name.\n *\n * @type {String}\n * @default 'event-router'\n */\n channelName: 'event-router',\n\n /**\n * Get the router's Radio channel instance\n *\n * @public\n * @method getChannel\n * @memberOf EventRouter\n * @returns {Backbone.Radio.Channel}\n */\n getChannel: function() {\n return this._ch;\n },\n\n /**\n * For each routeTrigger it adds a route to Backbone.Router\n *\n * @private\n * @method _initRoutes\n * @memberOf EventRouter\n */\n _initRoutes: function() {\n this._routeTriggers = _.result(this, 'routeTriggers') || {};\n\n _.each(this._routeTriggers, this._addRouteTrigger, this);\n },\n\n /**\n * Adds a route(s) to Backbone.Router which on route triggers\n * the appropriate event\n *\n * @private\n * @method _addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n */\n _addRouteTrigger: function(routes, event){\n // handle any route as an array by default for the _.each\n routes = _.isArray(routes) ? routes : [routes];\n\n _.each(routes, function(route) {\n this.route(route, event, _.bind(this._ch.trigger, this._ch, event));\n }, this);\n },\n\n /**\n * Adds a routeTrigger, and route(s) to Backbone.Router\n * which on route triggers the appropriate event.\n *\n * @public\n * @method addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n addRouteTrigger: function(routes, event){\n this._routeTriggers[event] = routes;\n this._addRouteTrigger(routes, event);\n\n return this;\n },\n\n /**\n * Overrides `Backbone.Router.route()\n * Like Backbone.Router.Route but with before events\n * It also temporarily stores the event for understanding\n * what route is currently being handled.\n *\n * @public\n * @method route\n * @param {String} route - Route string\n * @param {String} [name] - Name of route\n * @param {String} callback - Function called on route\n * @event EventRouter#before:route - passes route name and route arguments\n * @event EventRouter#before:route:{event_name} - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n route: function(route, name, callback) {\n if (_.isFunction(name)) {\n callback = name;\n name = '';\n }\n if (!callback) {\n callback = this[name];\n }\n\n var wrappedCallback = _.bind(function() {\n\n var args = _.drop(arguments, 0);\n\n //trigger before: events that match currently triggered events\n this.trigger('before:route', name, args);\n this.trigger.apply(this, ['before:route:' + name].concat(args));\n\n this._storeRouteTrigger([name].concat(args));\n callback.apply(this, args);\n this._clearRouteTrigger();\n\n }, this);\n\n return Backbone.Router.prototype.route.call(this, route, name, wrappedCallback);\n },\n\n /**\n * Stores the route name and route arguments on a stack\n *\n * @private\n * @method _storeRouteTrigger\n * @param {Array} args - Array of route name and route arguments\n * @memberOf EventRouter\n */\n _storeRouteTrigger: function(args){\n this._routeArgs = this._routeArgs || [];\n this._routeArgs.push(args);\n },\n\n\n /**\n * Gets the top of the triggered route store stack\n *\n * @private\n * @method _getCurrentRouteTrigger\n * @memberOf EventRouter\n * @returns {Array}\n */\n _getCurrentRouteTrigger: function(){\n return _.last(this._routeArgs) || [];\n },\n\n /**\n * Pops the latests route triggered off of the store stack\n *\n * @private\n * @method _clearRouteTrigger\n * @memberOf EventRouter\n */\n _clearRouteTrigger: function(){\n this._routeArgs.pop();\n },\n\n /**\n * Checks to see if the current event being tests is the latest\n * route being handled by comparing the route name and arguments\n *\n * @private\n * @method _isTriggeredFromRoute\n * @memberOf EventRouter\n * @returns {Boolean}\n */\n _isTriggeredFromRoute: function(){\n var currentRoute = this._getCurrentRouteTrigger();\n\n if(arguments.length !== currentRoute.length){\n return false;\n }\n\n return (arguments.length === _.union(arguments, this.currentRoute).length);\n },\n\n /**\n * Takes a event string and any arguments passed to that event\n * And if not initiated by a route, translates the event into a\n * URL and navigates to it without re-triggering the route\n *\n * @public\n * @method navigateFromEvent\n * @param {String} event - Event string\n * @event EventRouter#noMatch - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n navigateFromEvent: function(event) {\n var route = this.getDefaultRoute(event);\n\n // if no matching route exists do nothing\n if(!route) {\n this.trigger.apply(this, ['noMatch'].concat(arguments));\n return this;\n }\n\n if(this._isTriggeredFromRoute.apply(this, arguments)) {\n return this;\n }\n\n var eventArgs = _.drop(arguments, 0);\n\n var translatedRoute = this.translateRoute(route, eventArgs);\n\n // update URL without triggering the route\n return this.navigate(translatedRoute, { trigger: false });\n },\n\n /**\n * Get the default route string\n * Either the first of the array or the passed in event if singular\n *\n * @public\n * @method getDefaultRoute\n * @memberOf EventRouter\n * @returns {String}\n */\n getDefaultRoute: function(event) {\n var routes = this._routeTriggers[event];\n\n return _.isArray(routes) ? routes[0] : routes;\n },\n\n /**\n * Finds the next name params (ie: :param) and replaces it with the arg\n *\n * @private\n * @method _replaceParam\n * @param {String} route - Route string\n * @param {String|Number} arg - value to replace named param\n * @memberOf EventRouter\n * @returns {String}\n */\n _replaceParam: function(route, arg){\n // https://github.com/jashkenas/backbone/blob/1.2.1/backbone.js#L1425\n var namedParam = /(\\(\\?)?:\\w+/;\n\n return route.replace(namedParam, arg);\n },\n\n /**\n * Takes a route string and an array or arguments\n * and returns a url with the named params replaced with the argument values\n *\n * @public\n * @method translateRoute\n * @param {String} route - Route string\n * @param {Array} eventArgs - Passed event arguments\n * @memberOf EventRouter\n * @returns {String}\n */\n translateRoute: function(route, eventArgs) {\n return _.reduce(eventArgs, this._replaceParam, route);\n }\n });\n\n var backbone_eventrouter = EventRouter;\n\n return backbone_eventrouter;\n\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["/source/backbone.eventrouter.js"],"names":["global","factory","exports","module","require","define","amd","Backbone","EventRouter","_","Radio","this","Router","extend","constructor","options","apply","arguments","pick","_ch","channel","result","_initRoutes","listenTo","navigateFromEvent","channelName","getChannel","_routeTriggers","each","_addRouteTrigger","routes","event","isArray","route","bind","trigger","addRouteTrigger","_route","name","callback","isFunction","wrappedCallback","args","drop","concat","_storeRouteTrigger","_clearRouteTrigger","prototype","call","_routeArgs","push","_getCurrentRouteTrigger","last","pop","_isTriggeredFromRoute","currentRoute","length","union","getDefaultRoute","eventArgs","translatedRoute","translateRoute","navigate","_replaceParam","arg","namedParam","replace","reduce","backbone_eventrouter"],"mappings":"CAMA,SAAWA,EAAQC,GACE,gBAAZC,UAA0C,mBAAXC,QAAyBA,OAAOD,QAAUD,EAAQG,QAAQ,cAAeA,QAAQ,YAAaA,QAAQ,mBAC1H,kBAAXC,SAAyBA,OAAOC,IAAMD,QAAQ,aAAc,WAAY,kBAAmBJ,GAClGD,EAAOO,SAASC,YAAcP,EAAQD,EAAOS,EAAGT,EAAOO,SAAUP,EAAOU,QACxEC,KAAM,SAAUF,EAAGF,EAAUG,GAAS,YAEtC,IAAIF,GAAcD,EAASC,YAAcD,EAASK,OAAOC,QASvDC,YAAa,SAASC,GACpBA,EAAUN,EAAEI,UAAWE,GAIvBR,EAASK,OAAOI,MAAML,KAAMM,WAE5BR,EAAEI,OAAOF,KAAMF,EAAES,KAAKH,GAAU,cAAe,mBAE/CJ,KAAKQ,IAAMZ,EAASG,MAAMU,QAAQX,EAAEY,OAAOV,KAAM,gBAEjDA,KAAKW,cAELX,KAAKY,SAASZ,KAAKQ,IAAK,MAAOR,KAAKa,oBAStCC,YAAa,eAUbC,WAAY,WACV,MAAOf,MAAKQ,KAUdG,YAAa,WACXX,KAAKgB,eAAiBlB,EAAEY,OAAOV,KAAM,qBAErCF,EAAEmB,KAAKjB,KAAKgB,eAAgBhB,KAAKkB,iBAAkBlB,OAarDkB,iBAAkB,SAASC,EAAQC,GAEjCD,EAASrB,EAAEuB,QAAQF,GAAUA,GAAUA,GAEvCrB,EAAEmB,KAAKE,EAAQ,SAASG,GACtBtB,KAAKsB,MAAMA,EAAOF,EAAOtB,EAAEyB,KAAKvB,KAAKQ,IAAIgB,QAASxB,KAAKQ,IAAKY,KAC3DpB,OAcLyB,gBAAiB,SAASN,EAAQC,GAIhC,MAHApB,MAAKgB,eAAeI,GAASD,EAC7BnB,KAAKkB,iBAAiBC,EAAQC,GAEvBpB,MAmBTsB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GAAID,GAASnB,KAAKgB,eAAeI,EAEjC,OAAOtB,GAAEuB,QAAQF,GAAUA,EAAO,GAAKA,GAazCiC,cAAe,SAAS9B,EAAO+B,GAE7B,GAAIC,GAAa,aAEjB,OAAOhC,GAAMiC,QAAQD,EAAYD,IAcnCH,eAAgB,SAAS5B,EAAO0B,GAC9B,MAAOlD,GAAE0D,OAAOR,EAAWhD,KAAKoD,cAAe9B,MAI/CmC,EAAuB5D,CAE3B,OAAO4D","file":"backbone.eventrouter.min.js","sourcesContent":["/**\n * backbone.eventrouter - A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel\n * @version v0.2.0\n * @link https://github.com/RoundingWellOS/backbone.eventrouter\n * @license MIT\n */\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('underscore'), require('backbone'), require('backbone.radio')) :\n typeof define === 'function' && define.amd ? define(['underscore', 'backbone', 'backbone.radio'], factory) :\n global.Backbone.EventRouter = factory(global._, global.Backbone, global.Radio)\n}(this, function (_, Backbone, Radio) { 'use strict';\n\n var EventRouter = Backbone.EventRouter = Backbone.Router.extend({\n\n /**\n * @public\n * @constructs EventRouter\n * @param {Object} [options] - Settings for the EventRouter\n * @param {Boolean} [options.channelName]\n * @param {Boolean} [options.routeTriggers]\n */\n constructor: function(options) {\n options = _.extend({}, options);\n\n // Backbone.Router routes are added first\n // Routes can be added after the triggerRoutes with the Backbone.Router API\n Backbone.Router.apply(this, arguments);\n\n _.extend(this, _.pick(options, ['channelName', 'routeTriggers']));\n\n this._ch = Backbone.Radio.channel(_.result(this, 'channelName'));\n\n this._initRoutes();\n\n this.listenTo(this._ch, 'all', this.navigateFromEvent);\n },\n\n /**\n * The Radio Channel name.\n *\n * @type {String}\n * @default 'event-router'\n */\n channelName: 'event-router',\n\n /**\n * Get the router's Radio channel instance\n *\n * @public\n * @method getChannel\n * @memberOf EventRouter\n * @returns {Backbone.Radio.Channel}\n */\n getChannel: function() {\n return this._ch;\n },\n\n /**\n * For each routeTrigger it adds a route to Backbone.Router\n *\n * @private\n * @method _initRoutes\n * @memberOf EventRouter\n */\n _initRoutes: function() {\n this._routeTriggers = _.result(this, 'routeTriggers') || {};\n\n _.each(this._routeTriggers, this._addRouteTrigger, this);\n },\n\n /**\n * Adds a route(s) to Backbone.Router which on route triggers\n * the appropriate event\n *\n * @private\n * @method _addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n */\n _addRouteTrigger: function(routes, event){\n // handle any route as an array by default for the _.each\n routes = _.isArray(routes) ? routes : [routes];\n\n _.each(routes, function(route) {\n this.route(route, event, _.bind(this._ch.trigger, this._ch, event));\n }, this);\n },\n\n /**\n * Adds a routeTrigger, and route(s) to Backbone.Router\n * which on route triggers the appropriate event.\n *\n * @public\n * @method addRouteTrigger\n * @param {Array|String} routes - Route string or array of route strings\n * @param {String} event - Event string to trigger on route\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n addRouteTrigger: function(routes, event){\n this._routeTriggers[event] = routes;\n this._addRouteTrigger(routes, event);\n\n return this;\n },\n\n /**\n * Overrides `Backbone.Router.route()\n * Like Backbone.Router.Route but with before events\n * It also temporarily stores the event for understanding\n * what route is currently being handled.\n *\n * @public\n * @method route\n * @param {String} route - Route string\n * @param {String} [name] - Name of route\n * @param {String} callback - Function called on route\n * @event EventRouter#before:route - passes route name and route arguments\n * @event EventRouter#before:route:{event_name} - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n route: function(route, name, callback) {\n if (_.isFunction(name)) {\n callback = name;\n name = '';\n }\n if (!callback) {\n callback = this[name];\n }\n\n var wrappedCallback = _.bind(function() {\n\n var args = _.drop(arguments, 0);\n\n //trigger before: events that match currently triggered events\n this.trigger('before:route', name, args);\n this.trigger.apply(this, ['before:route:' + name].concat(args));\n\n this._storeRouteTrigger([name].concat(args));\n callback.apply(this, args);\n this._clearRouteTrigger();\n\n }, this);\n\n return Backbone.Router.prototype.route.call(this, route, name, wrappedCallback);\n },\n\n /**\n * Stores the route name and route arguments on a stack\n *\n * @private\n * @method _storeRouteTrigger\n * @param {Array} args - Array of route name and route arguments\n * @memberOf EventRouter\n */\n _storeRouteTrigger: function(args){\n this._routeArgs = this._routeArgs || [];\n this._routeArgs.push(args);\n },\n\n\n /**\n * Gets the top of the triggered route store stack\n *\n * @private\n * @method _getCurrentRouteTrigger\n * @memberOf EventRouter\n * @returns {Array}\n */\n _getCurrentRouteTrigger: function(){\n return _.last(this._routeArgs) || [];\n },\n\n /**\n * Pops the latests route triggered off of the store stack\n *\n * @private\n * @method _clearRouteTrigger\n * @memberOf EventRouter\n */\n _clearRouteTrigger: function(){\n this._routeArgs.pop();\n },\n\n /**\n * Checks to see if the current event being tests is the latest\n * route being handled by comparing the route name and arguments\n *\n * @private\n * @method _isTriggeredFromRoute\n * @memberOf EventRouter\n * @returns {Boolean}\n */\n _isTriggeredFromRoute: function(){\n var currentRoute = this._getCurrentRouteTrigger();\n\n if(arguments.length !== currentRoute.length){\n return false;\n }\n\n return (arguments.length === _.union(arguments, this.currentRoute).length);\n },\n\n /**\n * Takes a event string and any arguments passed to that event\n * And if not initiated by a route, translates the event into a\n * URL and navigates to it without re-triggering the route\n *\n * @public\n * @method navigateFromEvent\n * @param {String} event - Event string\n * @event EventRouter#noMatch - passes route arguments\n * @memberOf EventRouter\n * @returns {EventRouter}\n */\n navigateFromEvent: function(event) {\n var route = this.getDefaultRoute(event);\n\n // if no matching route exists do nothing\n if(!route) {\n var args = _.drop(arguments, 0);\n this.trigger.apply(this, ['noMatch'].concat(args));\n return this;\n }\n\n if(this._isTriggeredFromRoute.apply(this, arguments)) {\n return this;\n }\n\n var eventArgs = _.drop(arguments, 1);\n\n var translatedRoute = this.translateRoute(route, eventArgs);\n\n // update URL without triggering the route\n return this.navigate(translatedRoute, { trigger: false });\n },\n\n /**\n * Get the default route string\n * Either the first of the array or the passed in event if singular\n *\n * @public\n * @method getDefaultRoute\n * @memberOf EventRouter\n * @returns {String}\n */\n getDefaultRoute: function(event) {\n var routes = this._routeTriggers[event];\n\n return _.isArray(routes) ? routes[0] : routes;\n },\n\n /**\n * Finds the next name params (ie: :param) and replaces it with the arg\n *\n * @private\n * @method _replaceParam\n * @param {String} route - Route string\n * @param {String|Number} arg - value to replace named param\n * @memberOf EventRouter\n * @returns {String}\n */\n _replaceParam: function(route, arg){\n // https://github.com/jashkenas/backbone/blob/1.2.1/backbone.js#L1425\n var namedParam = /(\\(\\?)?:\\w+/;\n\n return route.replace(namedParam, arg);\n },\n\n /**\n * Takes a route string and an array or arguments\n * and returns a url with the named params replaced with the argument values\n *\n * @public\n * @method translateRoute\n * @param {String} route - Route string\n * @param {Array} eventArgs - Passed event arguments\n * @memberOf EventRouter\n * @returns {String}\n */\n translateRoute: function(route, eventArgs) {\n return _.reduce(eventArgs, this._replaceParam, route);\n }\n });\n\n var backbone_eventrouter = EventRouter;\n\n return backbone_eventrouter;\n\n}));\n//# sourceMappingURL=./backbone.eventrouter.js.map"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/package.json b/package.json index 3d292fc..4e708a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backbone.eventrouter", - "version": "0.1.1", + "version": "0.2.0", "description": "A highly opinionated, simplistic Backbone.Router coupled with a Backbone.Radio.Channel", "main": "./dist/backbone.eventrouter.js", "engine": "node >= 4.0.0",