Comparing version 1.2.1 to 1.2.2
@@ -40,2 +40,3 @@ "use strict"; | ||
this.state = undefined; | ||
this.currentSequence = 0; | ||
@@ -74,3 +75,3 @@ this.recognizer = new RouteRecognizer(); | ||
// Create a new transition to the destination route. | ||
newTransition = new Transition(this, intent, newState); | ||
newTransition = new Transition(this, intent, newState, undefined, this.activeTransition); | ||
@@ -641,3 +642,23 @@ // Abort and usurp any previously active transition. | ||
if (urlMethod === 'replace') { | ||
// transitions during the initial transition must always use replaceURL. | ||
// When the app boots, you are at a url, e.g. /foo. If some handler | ||
// redirects to bar as part of the initial transition, you don't want to | ||
// add a history entry for /foo. If you do, pressing back will immediately | ||
// hit the redirect again and take you back to /bar, thus killing the back | ||
// button | ||
var initial = transition.isCausedByInitialTransition; | ||
// say you are at / and you click a link to route /foo. In /foo's | ||
// handler, the transition is aborted using replacewith('/bar'). | ||
// Because the current url is still /, the history entry for / is | ||
// removed from the history. Clicking back will take you to the page | ||
// you were on before /, which is often not even the app, thus killing | ||
// the back button. That's why updateURL is always correct for an | ||
// aborting transition that's not the initial transition | ||
var replaceAndNotAborting = ( | ||
urlMethod === 'replace' && | ||
!transition.isCausedByAbortingTransition | ||
); | ||
if (initial || replaceAndNotAborting) { | ||
router.replaceURL(url); | ||
@@ -644,0 +665,0 @@ } else { |
@@ -23,3 +23,3 @@ "use strict"; | ||
*/ | ||
function Transition(router, intent, state, error) { | ||
function Transition(router, intent, state, error, previousTransition) { | ||
var transition = this; | ||
@@ -48,2 +48,14 @@ this.state = state || router.state; | ||
// if you're doing multiple redirects, need the new transition to know if it | ||
// is actually part of the first transition or not. Any further redirects | ||
// in the initial transition also need to know if they are part of the | ||
// initial transition | ||
this.isCausedByAbortingTransition = !!previousTransition; | ||
this.isCausedByInitialTransition = ( | ||
previousTransition && ( | ||
previousTransition.isCausedByInitialTransition || | ||
previousTransition.sequence === 0 | ||
) | ||
); | ||
if (state) { | ||
@@ -67,12 +79,5 @@ this.params = state.params; | ||
this.sequence = Transition.currentSequence++; | ||
this.promise = state.resolve(checkForAbort, this)['catch'](function(result) { | ||
if (result.wasAborted || transition.isAborted) { | ||
return Promise.reject(logAbort(transition)); | ||
} else { | ||
transition.trigger('error', result.error, transition, result.handlerWithError); | ||
transition.abort(); | ||
return Promise.reject(result.error); | ||
} | ||
}, promiseLabel('Handle Abort')); | ||
this.sequence = router.currentSequence++; | ||
this.promise = state.resolve(checkForAbort, this)['catch']( | ||
catchHandlerForTransition(transition), promiseLabel('Handle Abort')); | ||
} else { | ||
@@ -90,4 +95,15 @@ this.promise = Promise.resolve(this.state); | ||
Transition.currentSequence = 0; | ||
function catchHandlerForTransition(transition) { | ||
return function(result) { | ||
if (result.wasAborted || transition.isAborted) { | ||
return Promise.reject(logAbort(transition)); | ||
} else { | ||
transition.trigger('error', result.error, transition, result.handlerWithError); | ||
transition.abort(); | ||
return Promise.reject(result.error); | ||
} | ||
}; | ||
} | ||
Transition.prototype = { | ||
@@ -94,0 +110,0 @@ targetName: null, |
@@ -1,1 +0,1 @@ | ||
(function(e,r,t){var n,a,i,s;(function(){var e={},r={};n=function(r,t,n){e[r]={deps:t,callback:n}};s=i=a=function(t){if(r[t]){return r[t]}r[t]={};if(!e[t]){throw new Error("Could not find module "+t)}var n=e[t],i=n.deps,s=n.callback,o=[],l;for(var u=0,h=i.length;u<h;u++){if(i[u]==="exports"){o.push(l={})}else{o.push(a(d(i[u])))}}var f=s.apply(this,o);return r[t]=l||f;function d(e){if(e.charAt(0)!=="."){return e}var r=e.split("/");var n=t.split("/").slice(0,-1);for(var a=0,i=r.length;a<i;a++){var s=r[a];if(s===".."){n.pop()}else if(s==="."){continue}else{n.push(s)}}return n.join("/")}}})();n("router/handler-info",["./utils","rsvp/promise","exports"],function(e,r,t){"use strict";var n=e.bind;var a=e.merge;var i=e.promiseLabel;var s=e.applyHook;var o=e.isPromise;var l=r["default"];var u=Object.freeze({});function h(e){var r=e||{};this._handler=u;if(r.handler){var t=r.name;this.handlerPromise=l.resolve(r.handler);if(o(r.handler)){this.handlerPromise=this.handlerPromise.then(n(this,this.updateHandler));r.handler=undefined}else if(r.handler){r.handler._handlerName=t}}a(this,r);this.initialize(r)}h.prototype={name:null,getHandler:function(){},fetchHandler:function(){var e=this.getHandler(this.name);this.handlerPromise=l.resolve(e);if(o(e)){this.handlerPromise=this.handlerPromise.then(n(this,this.updateHandler))}else if(e){e._handlerName=this.name;return this.handler=e}return this.handler=undefined},_handlerPromise:undefined,params:null,context:null,factory:null,initialize:function(){},log:function(e,r){if(e.log){e.log(this.name+": "+r)}},promiseLabel:function(e){return i("'"+this.name+"' "+e)},getUnresolved:function(){return this},serialize:function(){return this.params||{}},updateHandler:function(e){e._handlerName=this.name;return this.handler=e},resolve:function(e,r){var t=n(this,this.checkForAbort,e),a=n(this,this.runBeforeModelHook,r),i=n(this,this.getModel,r),s=n(this,this.runAfterModelHook,r),o=n(this,this.becomeResolved,r),u=this;return l.resolve(this.handlerPromise,this.promiseLabel("Start handler")).then(function(e){return l.resolve(e).then(t,null,u.promiseLabel("Check for abort")).then(a,null,u.promiseLabel("Before model")).then(t,null,u.promiseLabel("Check if aborted during 'beforeModel' hook")).then(i,null,u.promiseLabel("Model")).then(t,null,u.promiseLabel("Check if aborted in 'model' hook")).then(s,null,u.promiseLabel("After model")).then(t,null,u.promiseLabel("Check if aborted in 'afterModel' hook")).then(o,null,u.promiseLabel("Become resolved"))},function(e){throw e})},runBeforeModelHook:function(e){if(e.trigger){e.trigger(true,"willResolveModel",e,this.handler)}return this.runSharedModelHook(e,"beforeModel",[])},runAfterModelHook:function(e,r){var t=this.name;this.stashResolvedModel(e,r);return this.runSharedModelHook(e,"afterModel",[r]).then(function(){return e.resolvedModels[t]},null,this.promiseLabel("Ignore fulfillment value and return model value"))},runSharedModelHook:function(e,r,t){this.log(e,"calling "+r+" hook");if(this.queryParams){t.push(this.queryParams)}t.push(e);var n=s(this.handler,r,t);if(n&&n.isTransition){n=null}return l.resolve(n,this.promiseLabel("Resolve value returned from one of the model hooks"))},getModel:null,checkForAbort:function(e,r){return l.resolve(e(),this.promiseLabel("Check for abort")).then(function(){return r},null,this.promiseLabel("Ignore fulfillment value and continue"))},stashResolvedModel:function(e,r){e.resolvedModels=e.resolvedModels||{};e.resolvedModels[this.name]=r},becomeResolved:function(e,r){var t=this.serialize(r);if(e){this.stashResolvedModel(e,r);e.params=e.params||{};e.params[this.name]=t}return this.factory("resolved",{context:r,name:this.name,handler:this.handler,params:t})},shouldSupercede:function(e){if(!e){return true}var r=e.context===this.context;return e.name!==this.name||this.hasOwnProperty("context")&&!r||this.hasOwnProperty("params")&&!f(this.params,e.params)}};Object.defineProperty(h.prototype,"handler",{get:function(){if(this._handler!==u){return this._handler}return this.fetchHandler()},set:function(e){return this._handler=e}});Object.defineProperty(h.prototype,"handlerPromise",{get:function(){if(this._handlerPromise){return this._handlerPromise}this.fetchHandler();return this._handlerPromise},set:function(e){return this._handlerPromise=e}});function f(e,r){if(!e^!r){return false}if(!e){return true}for(var t in e){if(e.hasOwnProperty(t)&&e[t]!==r[t]){return false}}return true}t["default"]=h});n("router/handler-info/factory",["router/handler-info/resolved-handler-info","router/handler-info/unresolved-handler-info-by-object","router/handler-info/unresolved-handler-info-by-param","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r["default"];var s=t["default"];o.klasses={resolved:a,param:s,object:i};function o(e,r){var t=o.klasses[e],n=new t(r||{});n.factory=o;return n}n["default"]=o});n("router/handler-info/resolved-handler-info",["../handler-info","router/utils","rsvp/promise","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r.subclass;var s=t["default"];var o=i(a,{resolve:function(e,r){if(r&&r.resolvedModels){r.resolvedModels[this.name]=this.context}return s.resolve(this,this.promiseLabel("Resolve"))},getUnresolved:function(){return this.factory("param",{name:this.name,handler:this.handler,params:this.params})},isResolved:true});n["default"]=o});n("router/handler-info/unresolved-handler-info-by-object",["../handler-info","router/utils","rsvp/promise","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r.subclass;var s=r.isParam;var o=t["default"];var l=i(a,{getModel:function(e){this.log(e,this.name+": resolving provided model");return o.resolve(this.context)},initialize:function(e){this.names=e.names||[];this.context=e.context},serialize:function(e){var r=e||this.context,t=this.names,n=this.serializer||this.handler&&this.handler.serialize;var a={};if(s(r)){a[t[0]]=r;return a}if(n){return n(r,t)}if(t.length!==1){return}var i=t[0];if(/_id$/.test(i)){a[i]=r.id}else{a[i]=r}return a}});n["default"]=l});n("router/handler-info/unresolved-handler-info-by-param",["../handler-info","router/utils","exports"],function(e,r,t){"use strict";var n=e["default"];var a=r.resolveHook;var i=r.merge;var s=r.subclass;var o=s(n,{initialize:function(e){this.params=e.params||{}},getModel:function(e){var r=this.params;if(e&&e.queryParams){r={};i(r,this.params);r.queryParams=e.queryParams}var t=this.handler;var n=a(t,"deserialize")||a(t,"model");return this.runSharedModelHook(e,n,[r])}});t["default"]=o});n("router/router",["route-recognizer","rsvp/promise","./utils","./transition-state","./transition","./transition-intent/named-transition-intent","./transition-intent/url-transition-intent","exports"],function(e,r,t,n,a,i,s,o){"use strict";var l=e["default"];var u=r["default"];var h=t.trigger;var f=t.log;var d=t.slice;var c=t.forEach;var v=t.merge;var m=t.extractQueryParams;var p=t.getChangelist;var g=t.promiseLabel;var y=t.callHook;var b=n["default"];var P=a.logAbort;var I=a.Transition;var w=a.TransitionAborted;var x=i["default"];var T=s["default"];var H=Array.prototype.pop;function q(e){var r=e||{};this.getHandler=r.getHandler||this.getHandler;this.getSerializer=r.getSerializer||this.getSerializer;this.updateURL=r.updateURL||this.updateURL;this.replaceURL=r.replaceURL||this.replaceURL;this.didTransition=r.didTransition||this.didTransition;this.willTransition=r.willTransition||this.willTransition;this.delegate=r.delegate||this.delegate;this.triggerEvent=r.triggerEvent||this.triggerEvent;this.log=r.log||this.log;this.dslCallBacks=[];this.state=undefined;this.activeTransition=undefined;this._changedQueryParams=undefined;this.oldState=undefined;this.currentHandlerInfos=undefined;this.state=undefined;this.recognizer=new l;this.reset()}function L(e,r){var t=!!this.activeTransition;var n=t?this.activeTransition.state:this.state;var a;var i=e.applyToState(n,this.recognizer,this.getHandler,r,this.getSerializer);var s=p(n.queryParams,i.queryParams);if(C(i.handlerInfos,n.handlerInfos)){if(s){a=this.queryParamsTransition(s,t,n,i);if(a){return a}}return this.activeTransition||new I(this)}if(r){R(this,i);return}a=new I(this,e,i);if(this.activeTransition){this.activeTransition.abort()}this.activeTransition=a;a.promise=a.promise.then(function(e){return M(a,e.state)},null,g("Settle transition promise when transition is finalized"));if(!t){j(this,i,a)}z(this,i,s);return a}q.prototype={map:function(e){this.recognizer.delegate=this.delegate;this.recognizer.map(e,function(e,r){for(var t=r.length-1,n=true;t>=0&&n;--t){var a=r[t];e.add(r,{as:a.handler});n=a.path==="/"||a.path===""||a.handler.slice(-6)===".index"}})},hasRoute:function(e){return this.recognizer.hasRoute(e)},getHandler:function(){},getSerializer:function(){},queryParamsTransition:function(e,r,t,n){var a=this;z(this,n,e);if(!r&&this.activeTransition){return this.activeTransition}else{var i=new I(this);i.queryParamsOnly=true;t.queryParams=E(this,n.handlerInfos,n.queryParams,i);i.promise=i.promise.then(function(e){k(i,t,true);if(a.didTransition){a.didTransition(a.currentHandlerInfos)}return e},null,g("Transition complete"));return i}},transitionByIntent:function(e){try{return L.apply(this,arguments)}catch(r){return new I(this,e,null,r)}},reset:function(){if(this.state){c(this.state.handlerInfos.slice().reverse(),function(e){var r=e.handler;y(r,"exit")})}this.oldState=undefined;this.state=new b;this.currentHandlerInfos=null},activeTransition:null,handleURL:function(e){var r=d.call(arguments);if(e.charAt(0)!=="/"){r[0]="/"+e}return U(this,r).method(null)},updateURL:function(){throw new Error("updateURL is not implemented")},replaceURL:function(e){this.updateURL(e)},transitionTo:function(){return U(this,arguments)},intermediateTransitionTo:function(){return U(this,arguments,true)},refresh:function(e){var r=this.activeTransition?this.activeTransition.state:this.state;var t=r.handlerInfos;var n={};for(var a=0,i=t.length;a<i;++a){var s=t[a];n[s.name]=s.params||{}}f(this,"Starting a refresh transition");var o=new x({name:t[t.length-1].name,pivotHandler:e||t[0].handler,contexts:[],queryParams:this._changedQueryParams||r.queryParams||{}});return this.transitionByIntent(o,false)},replaceWith:function(){return U(this,arguments).method("replace")},generate:function(e){var r=m(d.call(arguments,1)),t=r[0],n=r[1];var a=new x({name:e,contexts:t});var i=a.applyToState(this.state,this.recognizer,this.getHandler,null,this.getSerializer);var s={};for(var o=0,l=i.handlerInfos.length;o<l;++o){var u=i.handlerInfos[o];var h=u.serialize();v(s,h)}s.queryParams=n;return this.recognizer.generate(e,s)},applyIntent:function(e,r){var t=new x({name:e,contexts:r});var n=this.activeTransition&&this.activeTransition.state||this.state;return t.applyToState(n,this.recognizer,this.getHandler,null,this.getSerializer)},isActiveIntent:function(e,r,t,n){var a=n||this.state,i=a.handlerInfos,s,o;if(!i.length){return false}var l=i[i.length-1].name;var u=this.recognizer.handlersFor(l);var h=0;for(o=u.length;h<o;++h){s=i[h];if(s.name===e){break}}if(h===u.length){return false}var f=new b;f.handlerInfos=i.slice(0,h+1);u=u.slice(0,h+1);var d=new x({name:l,contexts:r});var c=d.applyToHandlers(f,u,this.getHandler,l,true,true,this.getSerializer);var m=C(c.handlerInfos,f.handlerInfos);if(!t||!m){return m}var g={};v(g,t);var y=a.queryParams;for(var P in y){if(y.hasOwnProperty(P)&&g.hasOwnProperty(P)){g[P]=y[P]}}return m&&!p(g,t)},isActive:function(e){var r=m(d.call(arguments,1));return this.isActiveIntent(e,r[0],r[1])},trigger:function(){var e=d.call(arguments);h(this,this.currentHandlerInfos,false,e)},log:null};function z(e,r,t){if(t){e._changedQueryParams=t.all;h(e,r.handlerInfos,true,["queryParamsDidChange",t.changed,t.all,t.removed]);e._changedQueryParams=null}}function R(e,r,t){var n=S(e.state,r);var a,i,s;for(a=0,i=n.exited.length;a<i;a++){s=n.exited[a].handler;delete s.context;y(s,"reset",true,t);y(s,"exit",t)}var o=e.oldState=e.state;e.state=r;var l=e.currentHandlerInfos=n.unchanged.slice();try{for(a=0,i=n.reset.length;a<i;a++){s=n.reset[a].handler;y(s,"reset",false,t)}for(a=0,i=n.updatedContext.length;a<i;a++){A(l,n.updatedContext[a],false,t)}for(a=0,i=n.entered.length;a<i;a++){A(l,n.entered[a],true,t)}}catch(u){e.state=o;e.currentHandlerInfos=o.handlerInfos;throw u}e.state.queryParams=E(e,l,r.queryParams,t)}function A(e,r,t,n){var a=r.handler,i=r.context;function s(a){if(t){y(a,"enter",n)}if(n&&n.isAborted){throw new w}a.context=i;y(a,"contextDidChange");y(a,"setup",i,n);if(n&&n.isAborted){throw new w}e.push(r)}if(!a){r.handlerPromise=r.handlerPromise.then(s)}else{s(a)}return true}function S(e,r){var t=e.handlerInfos;var n=r.handlerInfos;var a={updatedContext:[],exited:[],entered:[],unchanged:[],reset:undefined};var i,s=false,o,l;for(o=0,l=n.length;o<l;o++){var u=t[o],h=n[o];if(!u||u.handler!==h.handler){i=true}if(i){a.entered.push(h);if(u){a.exited.unshift(u)}}else if(s||u.context!==h.context){s=true;a.updatedContext.push(h)}else{a.unchanged.push(u)}}for(o=n.length,l=t.length;o<l;o++){a.exited.unshift(t[o])}a.reset=a.updatedContext.slice();a.reset.reverse();return a}function k(e,r){var t=e.urlMethod;if(!t){return}var n=e.router,a=r.handlerInfos,i=a[a.length-1].name,s={};for(var o=a.length-1;o>=0;--o){var l=a[o];v(s,l.params);if(l.handler.inaccessibleByURL){t=null}}if(t){s.queryParams=e._visibleQueryParams||r.queryParams;var u=n.recognizer.generate(i,s);if(t==="replace"){n.replaceURL(u)}else{n.updateURL(u)}}}function M(e,r){try{f(e.router,e.sequence,"Resolved all models on destination route; finalizing transition.");var t=e.router,n=r.handlerInfos;R(t,r,e);if(e.isAborted){t.state.handlerInfos=t.currentHandlerInfos;return u.reject(P(e))}k(e,r,e.intent.url);e.isActive=false;t.activeTransition=null;h(t,t.currentHandlerInfos,true,["didTransition"]);if(t.didTransition){t.didTransition(t.currentHandlerInfos)}f(t,e.sequence,"TRANSITION COMPLETE.");return n[n.length-1].handler}catch(a){if(!((a instanceof w))){var i=e.state.handlerInfos;e.trigger(true,"error",a,e,i[i.length-1].handler);e.abort()}throw a}}function U(e,r,t){var n=r[0]||"/";var a=r[r.length-1];var i={};if(a&&a.hasOwnProperty("queryParams")){i=H.call(r).queryParams}var s;if(r.length===0){f(e,"Updating query params");var o=e.state.handlerInfos;s=new x({name:o[o.length-1].name,contexts:[],queryParams:i})}else if(n.charAt(0)==="/"){f(e,"Attempting URL transition to "+n);s=new T({url:n})}else{f(e,"Attempting transition to "+n);s=new x({name:r[0],contexts:d.call(r,1),queryParams:i})}return e.transitionByIntent(s,t)}function C(e,r){if(e.length!==r.length){return false}for(var t=0,n=e.length;t<n;++t){if(e[t]!==r[t]){return false}}return true}function E(e,r,t,n){for(var a in t){if(t.hasOwnProperty(a)&&t[a]===null){delete t[a]}}var i=[];h(e,r,true,["finalizeQueryParamChange",t,i,n]);if(n){n._visibleQueryParams={}}var s={};for(var o=0,l=i.length;o<l;++o){var u=i[o];s[u.key]=u.value;if(n&&u.visible!==false){n._visibleQueryParams[u.key]=u.value}}return s}function j(e,r,t){var n=e.state.handlerInfos,a=[],i=null,s,o,l,u,f,d;u=n.length;for(l=0;l<u;l++){f=n[l];d=r.handlerInfos[l];if(!d||f.name!==d.name){i=l;break}if(!d.isResolved){a.push(f)}}if(i!==null){s=n.slice(i,u);o=function(e){for(var r=0,t=s.length;r<t;r++){if(s[r].name===e){return true}}return false}}h(e,n,true,["willTransition",t]);if(e.willTransition){e.willTransition(n,r.handlerInfos,t)}}o["default"]=q});n("router/transition-intent",["exports"],function(e){"use strict";function r(e){this.initialize(e);this.data=this.data||{}}r.prototype={initialize:null,applyToState:null};e["default"]=r});n("router/transition-intent/named-transition-intent",["../transition-intent","../transition-state","../handler-info/factory","../utils","exports"],function(e,r,t,n,a){"use strict";var i=e["default"];var s=r["default"];var o=t["default"];var l=n.isParam;var u=n.extractQueryParams;var h=n.merge;var f=n.subclass;a["default"]=f(i,{name:null,pivotHandler:null,contexts:null,queryParams:null,initialize:function(e){this.name=e.name;this.pivotHandler=e.pivotHandler;this.contexts=e.contexts||[];this.queryParams=e.queryParams},applyToState:function(e,r,t,n,a){var i=u([this.name].concat(this.contexts)),s=i[0],o=r.handlersFor(s[0]);var l=o[o.length-1].handler;return this.applyToHandlers(e,o,t,l,n,null,a)},applyToHandlers:function(e,r,t,n,a,i,o){var l,u;var f=new s;var d=this.contexts.slice(0);var c=r.length;if(this.pivotHandler){for(l=0,u=r.length;l<u;++l){if(r[l].handler===this.pivotHandler._handlerName){c=l;break}}}for(l=r.length-1;l>=0;--l){var v=r[l];var m=v.handler;var p=e.handlerInfos[l];var g=null;if(v.names.length>0){if(l>=c){g=this.createParamHandlerInfo(m,t,v.names,d,p)}else{var y=o(m);g=this.getHandlerInfoForDynamicSegment(m,t,v.names,d,p,n,l,y)}}else{g=this.createParamHandlerInfo(m,t,v.names,d,p)}if(i){g=g.becomeResolved(null,g.context);var b=p&&p.context;if(v.names.length>0&&g.context===b){g.params=p&&p.params}g.context=b}var P=p;if(l>=c||g.shouldSupercede(p)){c=Math.min(l,c);P=g}if(a&&!i){P=P.becomeResolved(null,P.context)}f.handlerInfos.unshift(P)}if(d.length>0){throw new Error("More context objects were passed than there are dynamic segments for the route: "+n)}if(!a){this.invalidateChildren(f.handlerInfos,c)}h(f.queryParams,this.queryParams||{});return f},invalidateChildren:function(e,r){for(var t=r,n=e.length;t<n;++t){var a=e[t];e[t]=a.getUnresolved()}},getHandlerInfoForDynamicSegment:function(e,r,t,n,a,i,s,u){var h;if(n.length>0){h=n[n.length-1];if(l(h)){return this.createParamHandlerInfo(e,r,t,n,a)}else{n.pop()}}else if(a&&a.name===e){return a}else{if(this.preTransitionState){var f=this.preTransitionState.handlerInfos[s];h=f&&f.context}else{return a}}return o("object",{name:e,getHandler:r,serializer:u,context:h,names:t})},createParamHandlerInfo:function(e,r,t,n,a){var i={};var s=t.length;while(s--){var u=a&&e===a.name&&a.params||{};var h=n[n.length-1];var f=t[s];if(l(h)){i[f]=""+n.pop()}else{if(u.hasOwnProperty(f)){i[f]=u[f]}else{throw new Error("You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route "+e)}}}return o("param",{name:e,getHandler:r,params:i})}})});n("router/transition-intent/url-transition-intent",["../transition-intent","../transition-state","../handler-info/factory","../utils","./../unrecognized-url-error","exports"],function(e,r,t,n,a,i){"use strict";var s=e["default"];var o=r["default"];var l=t["default"];var u=n.merge;var h=n.subclass;var f=a["default"];i["default"]=h(s,{url:null,initialize:function(e){this.url=e.url},applyToState:function(e,r,t){var n=new o;var a=r.recognize(this.url),i,s;if(!a){throw new f(this.url)}var h=false;var d=this.url;function c(e){if(e&&e.inaccessibleByURL){throw new f(d)}return e}for(i=0,s=a.length;i<s;++i){var v=a[i];var m=v.handler;var p=l("param",{name:m,getHandler:t,params:v.params});var g=p.handler;if(g){c(g)}else{p.handlerPromise=p.handlerPromise.then(c)}var y=e.handlerInfos[i];if(h||p.shouldSupercede(y)){h=true;n.handlerInfos[i]=p}else{n.handlerInfos[i]=y}}u(n.queryParams,a.queryParams);return n}})});n("router/transition-state",["./utils","rsvp/promise","exports"],function(e,r,t){"use strict";var n=e.forEach;var a=e.promiseLabel;var i=e.callHook;var s=r["default"];function o(){this.handlerInfos=[];this.queryParams={};this.params={}}o.prototype={promiseLabel:function(e){var r="";n(this.handlerInfos,function(e){if(r!==""){r+="."}r+=e.name});return a("'"+r+"': "+e)},resolve:function(e,r){var t=this.params;n(this.handlerInfos,function(e){t[e.name]=e.params||{}});r=r||{};r.resolveIndex=0;var a=this;var o=false;return s.resolve(null,this.promiseLabel("Start transition")).then(f,null,this.promiseLabel("Resolve handler"))["catch"](u,this.promiseLabel("Handle error"));function l(){return s.resolve(e(),a.promiseLabel("Check if should continue"))["catch"](function(e){o=true;return s.reject(e)},a.promiseLabel("Handle abort"))}function u(e){var t=a.handlerInfos;var n=r.resolveIndex>=t.length?t.length-1:r.resolveIndex;return s.reject({error:e,handlerWithError:a.handlerInfos[n].handler,wasAborted:o,state:a})}function h(e){var t=a.handlerInfos[r.resolveIndex].isResolved;a.handlerInfos[r.resolveIndex++]=e;if(!t){var n=e.handler;i(n,"redirect",e.context,r)}return l().then(f,null,a.promiseLabel("Resolve handler"))}function f(){if(r.resolveIndex===a.handlerInfos.length){return{error:null,state:a}}var e=a.handlerInfos[r.resolveIndex];return e.resolve(l,r).then(h,null,a.promiseLabel("Proceed"))}}};t["default"]=o});n("router/transition",["rsvp/promise","./utils","exports"],function(e,r,t){"use strict";var n=e["default"];var a=r.trigger;var i=r.slice;var s=r.log;var o=r.promiseLabel;function l(e,r,t,a){var i=this;this.state=t||e.state;this.intent=r;this.router=e;this.data=this.intent&&this.intent.data||{};this.resolvedModels={};this.queryParams={};this.promise=undefined;this.error=undefined;this.params=undefined;this.handlerInfos=undefined;this.targetName=undefined;this.pivotHandler=undefined;this.sequence=undefined;this.isAborted=false;this.isActive=true;if(a){this.promise=n.reject(a);this.error=a;return}if(t){this.params=t.params;this.queryParams=t.queryParams;this.handlerInfos=t.handlerInfos;var s=t.handlerInfos.length;if(s){this.targetName=t.handlerInfos[s-1].name}for(var h=0;h<s;++h){var f=t.handlerInfos[h];if(!f.isResolved){break}this.pivotHandler=f.handler}this.sequence=l.currentSequence++;this.promise=t.resolve(d,this)["catch"](function(e){if(e.wasAborted||i.isAborted){return n.reject(u(i))}else{i.trigger("error",e.error,i,e.handlerWithError);i.abort();return n.reject(e.error)}},o("Handle Abort"))}else{this.promise=n.resolve(this.state);this.params={}}function d(){if(i.isAborted){return n.reject(undefined,o("Transition aborted - reject"))}}}l.currentSequence=0;l.prototype={targetName:null,urlMethod:"update",intent:null,pivotHandler:null,resolveIndex:0,resolvedModels:null,state:null,queryParamsOnly:false,isTransition:true,isExiting:function(e){var r=this.handlerInfos;for(var t=0,n=r.length;t<n;++t){var a=r[t];if(a.name===e||a.handler===e){return false}}return true},promise:null,data:null,then:function(e,r,t){return this.promise.then(e,r,t)},"catch":function(e,r){return this.promise["catch"](e,r)},"finally":function(e,r){return this.promise["finally"](e,r)},abort:function(){if(this.isAborted){return this}s(this.router,this.sequence,this.targetName+": transition was aborted");this.intent.preTransitionState=this.router.state;this.isAborted=true;this.isActive=false;this.router.activeTransition=null;return this},retry:function(){this.abort();return this.router.transitionByIntent(this.intent,false)},method:function(e){this.urlMethod=e;return this},trigger:function(e){var r=i.call(arguments);if(typeof e==="boolean"){r.shift()}else{e=false}a(this.router,this.state.handlerInfos.slice(0,this.resolveIndex+1),e,r)},followRedirects:function(){var e=this.router;return this.promise["catch"](function(r){if(e.activeTransition){return e.activeTransition.followRedirects()}return n.reject(r)})},toString:function(){return"Transition (sequence "+this.sequence+")"},log:function(e){s(this.router,this.sequence,e)}};l.prototype.send=l.prototype.trigger;function u(e){s(e.router,e.sequence,"detected abort.");return new h}function h(e){this.message=e||"TransitionAborted";this.name="TransitionAborted"}t.Transition=l;t.logAbort=u;t.TransitionAborted=h});n("router/unrecognized-url-error",["./utils","exports"],function(e,r){"use strict";var t=e.oCreate;function n(e){this.message=e||"UnrecognizedURLError";this.name="UnrecognizedURLError";Error.call(this)}n.prototype=t(Error.prototype);r["default"]=n});n("router/utils",["exports"],function(e){"use strict";var r=Array.prototype.slice;var t;if(!Array.isArray){t=function(e){return Object.prototype.toString.call(e)==="[object Array]"}}else{t=Array.isArray}var n=t;e.isArray=n;function a(e){return(typeof e==="object"&&e!==null||typeof e==="function")&&typeof e.then==="function"}e.isPromise=a;function i(e,r){for(var t in r){if(r.hasOwnProperty(t)){e[t]=r[t]}}}var s=Object.create||function(e){function r(){}r.prototype=e;return new r};e.oCreate=s;function o(e){var t=e&&e.length,n,a;if(t&&t>0&&e[t-1]&&e[t-1].hasOwnProperty("queryParams")){a=e[t-1].queryParams;n=r.call(e,0,t-1);return[n,a]}else{return[e,null]}}e.extractQueryParams=o;function l(e){for(var r in e){if(typeof e[r]==="number"){e[r]=""+e[r]}else if(n(e[r])){for(var t=0,a=e[r].length;t<a;t++){e[r][t]=""+e[r][t]}}}}function u(e,r,t){if(!e.log){return}if(arguments.length===3){e.log("Transition #"+r+": "+t)}else{t=r;e.log(t)}}e.log=u;function h(e,t){var n=arguments;return function(a){var i=r.call(n,2);i.push(a);return t.apply(e,i)}}e.bind=h;function f(e){return typeof e==="string"||e instanceof String||typeof e==="number"||e instanceof Number}function d(e,r){for(var t=0,n=e.length;t<n&&false!==r(e[t]);t++){}}e.forEach=d;function c(e,r,t,n){if(e.triggerEvent){e.triggerEvent(r,t,n);return}var a=n.shift();if(!r){if(t){return}throw new Error("Could not trigger event '"+a+"'. There are no active handlers")}var i=false;function s(e,r,t){t.events[e].apply(t,r)}for(var o=r.length-1;o>=0;o--){var l=r[o],u=l.handler;if(!u){l.handlerPromise.then(h(null,s,a,n));continue}if(u.events&&u.events[a]){if(u.events[a].apply(u,n)===true){i=true}else{return}}}if(a==="error"&&n[0].name==="UnrecognizedURLError"){throw n[0]}else if(!i&&!t){throw new Error("Nothing handled the event '"+a+"'.")}}e.trigger=c;function v(e,r){var t;var a={all:{},changed:{},removed:{}};i(a.all,r);var s=false;l(e);l(r);for(t in e){if(e.hasOwnProperty(t)){if(!r.hasOwnProperty(t)){s=true;a.removed[t]=e[t]}}}for(t in r){if(r.hasOwnProperty(t)){if(n(e[t])&&n(r[t])){if(e[t].length!==r[t].length){a.changed[t]=r[t];s=true}else{for(var o=0,u=e[t].length;o<u;o++){if(e[t][o]!==r[t][o]){a.changed[t]=r[t];s=true}}}}else{if(e[t]!==r[t]){a.changed[t]=r[t];s=true}}}}return s&&a}e.getChangelist=v;function m(e){return"Router: "+e}e.promiseLabel=m;function p(e,r){function t(r){e.call(this,r||{})}t.prototype=s(e.prototype);i(t.prototype,r);return t}e.subclass=p;function g(e,r){if(!e){return}var t="_"+r;return e[t]&&t||e[r]&&r}function y(e,r,t,n){var a=g(e,r);return a&&e[a].call(e,t,n)}function b(e,r,t){var n=g(e,r);if(n){if(t.length===0){return e[n].call(e)}else if(t.length===1){return e[n].call(e,t[0])}else if(t.length===2){return e[n].call(e,t[0],t[1])}else{return e[n].apply(e,t)}}}e.merge=i;e.slice=r;e.isParam=f;e.coerceQueryParamsToString=l;e.callHook=y;e.resolveHook=g;e.applyHook=b});n("router",["./router/router","exports"],function(e,r){"use strict";var t=e["default"];r["default"]=t});n("route-recognizer",[],function(){return{"default":t}});n("rsvp",[],function(){return r});n("rsvp/promise",[],function(){return{"default":r.Promise}});window.Router=a("router")})(window,window.RSVP,window.RouteRecognizer); | ||
(function(e,r,t){var n,a,i,s;(function(){var e={},r={};n=function(r,t,n){e[r]={deps:t,callback:n}};s=i=a=function(t){if(r[t]){return r[t]}r[t]={};if(!e[t]){throw new Error("Could not find module "+t)}var n=e[t],i=n.deps,s=n.callback,o=[],l;for(var u=0,h=i.length;u<h;u++){if(i[u]==="exports"){o.push(l={})}else{o.push(a(d(i[u])))}}var f=s.apply(this,o);return r[t]=l||f;function d(e){if(e.charAt(0)!=="."){return e}var r=e.split("/");var n=t.split("/").slice(0,-1);for(var a=0,i=r.length;a<i;a++){var s=r[a];if(s===".."){n.pop()}else if(s==="."){continue}else{n.push(s)}}return n.join("/")}}})();n("router/handler-info",["./utils","rsvp/promise","exports"],function(e,r,t){"use strict";var n=e.bind;var a=e.merge;var i=e.promiseLabel;var s=e.applyHook;var o=e.isPromise;var l=r["default"];var u=Object.freeze({});function h(e){var r=e||{};this._handler=u;if(r.handler){var t=r.name;this.handlerPromise=l.resolve(r.handler);if(o(r.handler)){this.handlerPromise=this.handlerPromise.then(n(this,this.updateHandler));r.handler=undefined}else if(r.handler){r.handler._handlerName=t}}a(this,r);this.initialize(r)}h.prototype={name:null,getHandler:function(){},fetchHandler:function(){var e=this.getHandler(this.name);this.handlerPromise=l.resolve(e);if(o(e)){this.handlerPromise=this.handlerPromise.then(n(this,this.updateHandler))}else if(e){e._handlerName=this.name;return this.handler=e}return this.handler=undefined},_handlerPromise:undefined,params:null,context:null,factory:null,initialize:function(){},log:function(e,r){if(e.log){e.log(this.name+": "+r)}},promiseLabel:function(e){return i("'"+this.name+"' "+e)},getUnresolved:function(){return this},serialize:function(){return this.params||{}},updateHandler:function(e){e._handlerName=this.name;return this.handler=e},resolve:function(e,r){var t=n(this,this.checkForAbort,e),a=n(this,this.runBeforeModelHook,r),i=n(this,this.getModel,r),s=n(this,this.runAfterModelHook,r),o=n(this,this.becomeResolved,r),u=this;return l.resolve(this.handlerPromise,this.promiseLabel("Start handler")).then(function(e){return l.resolve(e).then(t,null,u.promiseLabel("Check for abort")).then(a,null,u.promiseLabel("Before model")).then(t,null,u.promiseLabel("Check if aborted during 'beforeModel' hook")).then(i,null,u.promiseLabel("Model")).then(t,null,u.promiseLabel("Check if aborted in 'model' hook")).then(s,null,u.promiseLabel("After model")).then(t,null,u.promiseLabel("Check if aborted in 'afterModel' hook")).then(o,null,u.promiseLabel("Become resolved"))},function(e){throw e})},runBeforeModelHook:function(e){if(e.trigger){e.trigger(true,"willResolveModel",e,this.handler)}return this.runSharedModelHook(e,"beforeModel",[])},runAfterModelHook:function(e,r){var t=this.name;this.stashResolvedModel(e,r);return this.runSharedModelHook(e,"afterModel",[r]).then(function(){return e.resolvedModels[t]},null,this.promiseLabel("Ignore fulfillment value and return model value"))},runSharedModelHook:function(e,r,t){this.log(e,"calling "+r+" hook");if(this.queryParams){t.push(this.queryParams)}t.push(e);var n=s(this.handler,r,t);if(n&&n.isTransition){n=null}return l.resolve(n,this.promiseLabel("Resolve value returned from one of the model hooks"))},getModel:null,checkForAbort:function(e,r){return l.resolve(e(),this.promiseLabel("Check for abort")).then(function(){return r},null,this.promiseLabel("Ignore fulfillment value and continue"))},stashResolvedModel:function(e,r){e.resolvedModels=e.resolvedModels||{};e.resolvedModels[this.name]=r},becomeResolved:function(e,r){var t=this.serialize(r);if(e){this.stashResolvedModel(e,r);e.params=e.params||{};e.params[this.name]=t}return this.factory("resolved",{context:r,name:this.name,handler:this.handler,params:t})},shouldSupercede:function(e){if(!e){return true}var r=e.context===this.context;return e.name!==this.name||this.hasOwnProperty("context")&&!r||this.hasOwnProperty("params")&&!f(this.params,e.params)}};Object.defineProperty(h.prototype,"handler",{get:function(){if(this._handler!==u){return this._handler}return this.fetchHandler()},set:function(e){return this._handler=e}});Object.defineProperty(h.prototype,"handlerPromise",{get:function(){if(this._handlerPromise){return this._handlerPromise}this.fetchHandler();return this._handlerPromise},set:function(e){return this._handlerPromise=e}});function f(e,r){if(!e^!r){return false}if(!e){return true}for(var t in e){if(e.hasOwnProperty(t)&&e[t]!==r[t]){return false}}return true}t["default"]=h});n("router/handler-info/factory",["router/handler-info/resolved-handler-info","router/handler-info/unresolved-handler-info-by-object","router/handler-info/unresolved-handler-info-by-param","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r["default"];var s=t["default"];o.klasses={resolved:a,param:s,object:i};function o(e,r){var t=o.klasses[e],n=new t(r||{});n.factory=o;return n}n["default"]=o});n("router/handler-info/resolved-handler-info",["../handler-info","router/utils","rsvp/promise","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r.subclass;var s=t["default"];var o=i(a,{resolve:function(e,r){if(r&&r.resolvedModels){r.resolvedModels[this.name]=this.context}return s.resolve(this,this.promiseLabel("Resolve"))},getUnresolved:function(){return this.factory("param",{name:this.name,handler:this.handler,params:this.params})},isResolved:true});n["default"]=o});n("router/handler-info/unresolved-handler-info-by-object",["../handler-info","router/utils","rsvp/promise","exports"],function(e,r,t,n){"use strict";var a=e["default"];var i=r.subclass;var s=r.isParam;var o=t["default"];var l=i(a,{getModel:function(e){this.log(e,this.name+": resolving provided model");return o.resolve(this.context)},initialize:function(e){this.names=e.names||[];this.context=e.context},serialize:function(e){var r=e||this.context,t=this.names,n=this.serializer||this.handler&&this.handler.serialize;var a={};if(s(r)){a[t[0]]=r;return a}if(n){return n(r,t)}if(t.length!==1){return}var i=t[0];if(/_id$/.test(i)){a[i]=r.id}else{a[i]=r}return a}});n["default"]=l});n("router/handler-info/unresolved-handler-info-by-param",["../handler-info","router/utils","exports"],function(e,r,t){"use strict";var n=e["default"];var a=r.resolveHook;var i=r.merge;var s=r.subclass;var o=s(n,{initialize:function(e){this.params=e.params||{}},getModel:function(e){var r=this.params;if(e&&e.queryParams){r={};i(r,this.params);r.queryParams=e.queryParams}var t=this.handler;var n=a(t,"deserialize")||a(t,"model");return this.runSharedModelHook(e,n,[r])}});t["default"]=o});n("router/router",["route-recognizer","rsvp/promise","./utils","./transition-state","./transition","./transition-intent/named-transition-intent","./transition-intent/url-transition-intent","exports"],function(e,r,t,n,a,i,s,o){"use strict";var l=e["default"];var u=r["default"];var h=t.trigger;var f=t.log;var d=t.slice;var c=t.forEach;var v=t.merge;var m=t.extractQueryParams;var p=t.getChangelist;var g=t.promiseLabel;var y=t.callHook;var b=n["default"];var P=a.logAbort;var I=a.Transition;var w=a.TransitionAborted;var x=i["default"];var T=s["default"];var H=Array.prototype.pop;function q(e){var r=e||{};this.getHandler=r.getHandler||this.getHandler;this.getSerializer=r.getSerializer||this.getSerializer;this.updateURL=r.updateURL||this.updateURL;this.replaceURL=r.replaceURL||this.replaceURL;this.didTransition=r.didTransition||this.didTransition;this.willTransition=r.willTransition||this.willTransition;this.delegate=r.delegate||this.delegate;this.triggerEvent=r.triggerEvent||this.triggerEvent;this.log=r.log||this.log;this.dslCallBacks=[];this.state=undefined;this.activeTransition=undefined;this._changedQueryParams=undefined;this.oldState=undefined;this.currentHandlerInfos=undefined;this.state=undefined;this.currentSequence=0;this.recognizer=new l;this.reset()}function L(e,r){var t=!!this.activeTransition;var n=t?this.activeTransition.state:this.state;var a;var i=e.applyToState(n,this.recognizer,this.getHandler,r,this.getSerializer);var s=p(n.queryParams,i.queryParams);if(U(i.handlerInfos,n.handlerInfos)){if(s){a=this.queryParamsTransition(s,t,n,i);if(a){return a}}return this.activeTransition||new I(this)}if(r){R(this,i);return}a=new I(this,e,i,undefined,this.activeTransition);if(this.activeTransition){this.activeTransition.abort()}this.activeTransition=a;a.promise=a.promise.then(function(e){return M(a,e.state)},null,g("Settle transition promise when transition is finalized"));if(!t){j(this,i,a)}z(this,i,s);return a}q.prototype={map:function(e){this.recognizer.delegate=this.delegate;this.recognizer.map(e,function(e,r){for(var t=r.length-1,n=true;t>=0&&n;--t){var a=r[t];e.add(r,{as:a.handler});n=a.path==="/"||a.path===""||a.handler.slice(-6)===".index"}})},hasRoute:function(e){return this.recognizer.hasRoute(e)},getHandler:function(){},getSerializer:function(){},queryParamsTransition:function(e,r,t,n){var a=this;z(this,n,e);if(!r&&this.activeTransition){return this.activeTransition}else{var i=new I(this);i.queryParamsOnly=true;t.queryParams=E(this,n.handlerInfos,n.queryParams,i);i.promise=i.promise.then(function(e){k(i,t,true);if(a.didTransition){a.didTransition(a.currentHandlerInfos)}return e},null,g("Transition complete"));return i}},transitionByIntent:function(e){try{return L.apply(this,arguments)}catch(r){return new I(this,e,null,r)}},reset:function(){if(this.state){c(this.state.handlerInfos.slice().reverse(),function(e){var r=e.handler;y(r,"exit")})}this.oldState=undefined;this.state=new b;this.currentHandlerInfos=null},activeTransition:null,handleURL:function(e){var r=d.call(arguments);if(e.charAt(0)!=="/"){r[0]="/"+e}return C(this,r).method(null)},updateURL:function(){throw new Error("updateURL is not implemented")},replaceURL:function(e){this.updateURL(e)},transitionTo:function(){return C(this,arguments)},intermediateTransitionTo:function(){return C(this,arguments,true)},refresh:function(e){var r=this.activeTransition?this.activeTransition.state:this.state;var t=r.handlerInfos;var n={};for(var a=0,i=t.length;a<i;++a){var s=t[a];n[s.name]=s.params||{}}f(this,"Starting a refresh transition");var o=new x({name:t[t.length-1].name,pivotHandler:e||t[0].handler,contexts:[],queryParams:this._changedQueryParams||r.queryParams||{}});return this.transitionByIntent(o,false)},replaceWith:function(){return C(this,arguments).method("replace")},generate:function(e){var r=m(d.call(arguments,1)),t=r[0],n=r[1];var a=new x({name:e,contexts:t});var i=a.applyToState(this.state,this.recognizer,this.getHandler,null,this.getSerializer);var s={};for(var o=0,l=i.handlerInfos.length;o<l;++o){var u=i.handlerInfos[o];var h=u.serialize();v(s,h)}s.queryParams=n;return this.recognizer.generate(e,s)},applyIntent:function(e,r){var t=new x({name:e,contexts:r});var n=this.activeTransition&&this.activeTransition.state||this.state;return t.applyToState(n,this.recognizer,this.getHandler,null,this.getSerializer)},isActiveIntent:function(e,r,t,n){var a=n||this.state,i=a.handlerInfos,s,o;if(!i.length){return false}var l=i[i.length-1].name;var u=this.recognizer.handlersFor(l);var h=0;for(o=u.length;h<o;++h){s=i[h];if(s.name===e){break}}if(h===u.length){return false}var f=new b;f.handlerInfos=i.slice(0,h+1);u=u.slice(0,h+1);var d=new x({name:l,contexts:r});var c=d.applyToHandlers(f,u,this.getHandler,l,true,true,this.getSerializer);var m=U(c.handlerInfos,f.handlerInfos);if(!t||!m){return m}var g={};v(g,t);var y=a.queryParams;for(var P in y){if(y.hasOwnProperty(P)&&g.hasOwnProperty(P)){g[P]=y[P]}}return m&&!p(g,t)},isActive:function(e){var r=m(d.call(arguments,1));return this.isActiveIntent(e,r[0],r[1])},trigger:function(){var e=d.call(arguments);h(this,this.currentHandlerInfos,false,e)},log:null};function z(e,r,t){if(t){e._changedQueryParams=t.all;h(e,r.handlerInfos,true,["queryParamsDidChange",t.changed,t.all,t.removed]);e._changedQueryParams=null}}function R(e,r,t){var n=S(e.state,r);var a,i,s;for(a=0,i=n.exited.length;a<i;a++){s=n.exited[a].handler;delete s.context;y(s,"reset",true,t);y(s,"exit",t)}var o=e.oldState=e.state;e.state=r;var l=e.currentHandlerInfos=n.unchanged.slice();try{for(a=0,i=n.reset.length;a<i;a++){s=n.reset[a].handler;y(s,"reset",false,t)}for(a=0,i=n.updatedContext.length;a<i;a++){A(l,n.updatedContext[a],false,t)}for(a=0,i=n.entered.length;a<i;a++){A(l,n.entered[a],true,t)}}catch(u){e.state=o;e.currentHandlerInfos=o.handlerInfos;throw u}e.state.queryParams=E(e,l,r.queryParams,t)}function A(e,r,t,n){var a=r.handler,i=r.context;function s(a){if(t){y(a,"enter",n)}if(n&&n.isAborted){throw new w}a.context=i;y(a,"contextDidChange");y(a,"setup",i,n);if(n&&n.isAborted){throw new w}e.push(r)}if(!a){r.handlerPromise=r.handlerPromise.then(s)}else{s(a)}return true}function S(e,r){var t=e.handlerInfos;var n=r.handlerInfos;var a={updatedContext:[],exited:[],entered:[],unchanged:[],reset:undefined};var i,s=false,o,l;for(o=0,l=n.length;o<l;o++){var u=t[o],h=n[o];if(!u||u.handler!==h.handler){i=true}if(i){a.entered.push(h);if(u){a.exited.unshift(u)}}else if(s||u.context!==h.context){s=true;a.updatedContext.push(h)}else{a.unchanged.push(u)}}for(o=n.length,l=t.length;o<l;o++){a.exited.unshift(t[o])}a.reset=a.updatedContext.slice();a.reset.reverse();return a}function k(e,r){var t=e.urlMethod;if(!t){return}var n=e.router,a=r.handlerInfos,i=a[a.length-1].name,s={};for(var o=a.length-1;o>=0;--o){var l=a[o];v(s,l.params);if(l.handler.inaccessibleByURL){t=null}}if(t){s.queryParams=e._visibleQueryParams||r.queryParams;var u=n.recognizer.generate(i,s);var h=e.isCausedByInitialTransition;var f=t==="replace"&&!e.isCausedByAbortingTransition;if(h||f){n.replaceURL(u)}else{n.updateURL(u)}}}function M(e,r){try{f(e.router,e.sequence,"Resolved all models on destination route; finalizing transition.");var t=e.router,n=r.handlerInfos;R(t,r,e);if(e.isAborted){t.state.handlerInfos=t.currentHandlerInfos;return u.reject(P(e))}k(e,r,e.intent.url);e.isActive=false;t.activeTransition=null;h(t,t.currentHandlerInfos,true,["didTransition"]);if(t.didTransition){t.didTransition(t.currentHandlerInfos)}f(t,e.sequence,"TRANSITION COMPLETE.");return n[n.length-1].handler}catch(a){if(!((a instanceof w))){var i=e.state.handlerInfos;e.trigger(true,"error",a,e,i[i.length-1].handler);e.abort()}throw a}}function C(e,r,t){var n=r[0]||"/";var a=r[r.length-1];var i={};if(a&&a.hasOwnProperty("queryParams")){i=H.call(r).queryParams}var s;if(r.length===0){f(e,"Updating query params");var o=e.state.handlerInfos;s=new x({name:o[o.length-1].name,contexts:[],queryParams:i})}else if(n.charAt(0)==="/"){f(e,"Attempting URL transition to "+n);s=new T({url:n})}else{f(e,"Attempting transition to "+n);s=new x({name:r[0],contexts:d.call(r,1),queryParams:i})}return e.transitionByIntent(s,t)}function U(e,r){if(e.length!==r.length){return false}for(var t=0,n=e.length;t<n;++t){if(e[t]!==r[t]){return false}}return true}function E(e,r,t,n){for(var a in t){if(t.hasOwnProperty(a)&&t[a]===null){delete t[a]}}var i=[];h(e,r,true,["finalizeQueryParamChange",t,i,n]);if(n){n._visibleQueryParams={}}var s={};for(var o=0,l=i.length;o<l;++o){var u=i[o];s[u.key]=u.value;if(n&&u.visible!==false){n._visibleQueryParams[u.key]=u.value}}return s}function j(e,r,t){var n=e.state.handlerInfos,a=[],i=null,s,o,l,u,f,d;u=n.length;for(l=0;l<u;l++){f=n[l];d=r.handlerInfos[l];if(!d||f.name!==d.name){i=l;break}if(!d.isResolved){a.push(f)}}if(i!==null){s=n.slice(i,u);o=function(e){for(var r=0,t=s.length;r<t;r++){if(s[r].name===e){return true}}return false}}h(e,n,true,["willTransition",t]);if(e.willTransition){e.willTransition(n,r.handlerInfos,t)}}o["default"]=q});n("router/transition-intent",["exports"],function(e){"use strict";function r(e){this.initialize(e);this.data=this.data||{}}r.prototype={initialize:null,applyToState:null};e["default"]=r});n("router/transition-intent/named-transition-intent",["../transition-intent","../transition-state","../handler-info/factory","../utils","exports"],function(e,r,t,n,a){"use strict";var i=e["default"];var s=r["default"];var o=t["default"];var l=n.isParam;var u=n.extractQueryParams;var h=n.merge;var f=n.subclass;a["default"]=f(i,{name:null,pivotHandler:null,contexts:null,queryParams:null,initialize:function(e){this.name=e.name;this.pivotHandler=e.pivotHandler;this.contexts=e.contexts||[];this.queryParams=e.queryParams},applyToState:function(e,r,t,n,a){var i=u([this.name].concat(this.contexts)),s=i[0],o=r.handlersFor(s[0]);var l=o[o.length-1].handler;return this.applyToHandlers(e,o,t,l,n,null,a)},applyToHandlers:function(e,r,t,n,a,i,o){var l,u;var f=new s;var d=this.contexts.slice(0);var c=r.length;if(this.pivotHandler){for(l=0,u=r.length;l<u;++l){if(r[l].handler===this.pivotHandler._handlerName){c=l;break}}}for(l=r.length-1;l>=0;--l){var v=r[l];var m=v.handler;var p=e.handlerInfos[l];var g=null;if(v.names.length>0){if(l>=c){g=this.createParamHandlerInfo(m,t,v.names,d,p)}else{var y=o(m);g=this.getHandlerInfoForDynamicSegment(m,t,v.names,d,p,n,l,y)}}else{g=this.createParamHandlerInfo(m,t,v.names,d,p)}if(i){g=g.becomeResolved(null,g.context);var b=p&&p.context;if(v.names.length>0&&g.context===b){g.params=p&&p.params}g.context=b}var P=p;if(l>=c||g.shouldSupercede(p)){c=Math.min(l,c);P=g}if(a&&!i){P=P.becomeResolved(null,P.context)}f.handlerInfos.unshift(P)}if(d.length>0){throw new Error("More context objects were passed than there are dynamic segments for the route: "+n)}if(!a){this.invalidateChildren(f.handlerInfos,c)}h(f.queryParams,this.queryParams||{});return f},invalidateChildren:function(e,r){for(var t=r,n=e.length;t<n;++t){var a=e[t];e[t]=a.getUnresolved()}},getHandlerInfoForDynamicSegment:function(e,r,t,n,a,i,s,u){var h;if(n.length>0){h=n[n.length-1];if(l(h)){return this.createParamHandlerInfo(e,r,t,n,a)}else{n.pop()}}else if(a&&a.name===e){return a}else{if(this.preTransitionState){var f=this.preTransitionState.handlerInfos[s];h=f&&f.context}else{return a}}return o("object",{name:e,getHandler:r,serializer:u,context:h,names:t})},createParamHandlerInfo:function(e,r,t,n,a){var i={};var s=t.length;while(s--){var u=a&&e===a.name&&a.params||{};var h=n[n.length-1];var f=t[s];if(l(h)){i[f]=""+n.pop()}else{if(u.hasOwnProperty(f)){i[f]=u[f]}else{throw new Error("You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route "+e)}}}return o("param",{name:e,getHandler:r,params:i})}})});n("router/transition-intent/url-transition-intent",["../transition-intent","../transition-state","../handler-info/factory","../utils","./../unrecognized-url-error","exports"],function(e,r,t,n,a,i){"use strict";var s=e["default"];var o=r["default"];var l=t["default"];var u=n.merge;var h=n.subclass;var f=a["default"];i["default"]=h(s,{url:null,initialize:function(e){this.url=e.url},applyToState:function(e,r,t){var n=new o;var a=r.recognize(this.url),i,s;if(!a){throw new f(this.url)}var h=false;var d=this.url;function c(e){if(e&&e.inaccessibleByURL){throw new f(d)}return e}for(i=0,s=a.length;i<s;++i){var v=a[i];var m=v.handler;var p=l("param",{name:m,getHandler:t,params:v.params});var g=p.handler;if(g){c(g)}else{p.handlerPromise=p.handlerPromise.then(c)}var y=e.handlerInfos[i];if(h||p.shouldSupercede(y)){h=true;n.handlerInfos[i]=p}else{n.handlerInfos[i]=y}}u(n.queryParams,a.queryParams);return n}})});n("router/transition-state",["./utils","rsvp/promise","exports"],function(e,r,t){"use strict";var n=e.forEach;var a=e.promiseLabel;var i=e.callHook;var s=r["default"];function o(){this.handlerInfos=[];this.queryParams={};this.params={}}o.prototype={promiseLabel:function(e){var r="";n(this.handlerInfos,function(e){if(r!==""){r+="."}r+=e.name});return a("'"+r+"': "+e)},resolve:function(e,r){var t=this.params;n(this.handlerInfos,function(e){t[e.name]=e.params||{}});r=r||{};r.resolveIndex=0;var a=this;var o=false;return s.resolve(null,this.promiseLabel("Start transition")).then(f,null,this.promiseLabel("Resolve handler"))["catch"](u,this.promiseLabel("Handle error"));function l(){return s.resolve(e(),a.promiseLabel("Check if should continue"))["catch"](function(e){o=true;return s.reject(e)},a.promiseLabel("Handle abort"))}function u(e){var t=a.handlerInfos;var n=r.resolveIndex>=t.length?t.length-1:r.resolveIndex;return s.reject({error:e,handlerWithError:a.handlerInfos[n].handler,wasAborted:o,state:a})}function h(e){var t=a.handlerInfos[r.resolveIndex].isResolved;a.handlerInfos[r.resolveIndex++]=e;if(!t){var n=e.handler;i(n,"redirect",e.context,r)}return l().then(f,null,a.promiseLabel("Resolve handler"))}function f(){if(r.resolveIndex===a.handlerInfos.length){return{error:null,state:a}}var e=a.handlerInfos[r.resolveIndex];return e.resolve(l,r).then(h,null,a.promiseLabel("Proceed"))}}};t["default"]=o});n("router/transition",["rsvp/promise","./utils","exports"],function(e,r,t){"use strict";var n=e["default"];var a=r.trigger;var i=r.slice;var s=r.log;var o=r.promiseLabel;function l(e,r,t,a,i){var s=this;this.state=t||e.state;this.intent=r;this.router=e;this.data=this.intent&&this.intent.data||{};this.resolvedModels={};this.queryParams={};this.promise=undefined;this.error=undefined;this.params=undefined;this.handlerInfos=undefined;this.targetName=undefined;this.pivotHandler=undefined;this.sequence=undefined;this.isAborted=false;this.isActive=true;if(a){this.promise=n.reject(a);this.error=a;return}this.isCausedByAbortingTransition=!!i;this.isCausedByInitialTransition=i&&(i.isCausedByInitialTransition||i.sequence===0);if(t){this.params=t.params;this.queryParams=t.queryParams;this.handlerInfos=t.handlerInfos;var l=t.handlerInfos.length;if(l){this.targetName=t.handlerInfos[l-1].name}for(var h=0;h<l;++h){var f=t.handlerInfos[h];if(!f.isResolved){break}this.pivotHandler=f.handler}this.sequence=e.currentSequence++;this.promise=t.resolve(d,this)["catch"](u(s),o("Handle Abort"))}else{this.promise=n.resolve(this.state);this.params={}}function d(){if(s.isAborted){return n.reject(undefined,o("Transition aborted - reject"))}}}function u(e){return function(r){if(r.wasAborted||e.isAborted){return n.reject(h(e))}else{e.trigger("error",r.error,e,r.handlerWithError);e.abort();return n.reject(r.error)}}}l.prototype={targetName:null,urlMethod:"update",intent:null,pivotHandler:null,resolveIndex:0,resolvedModels:null,state:null,queryParamsOnly:false,isTransition:true,isExiting:function(e){var r=this.handlerInfos;for(var t=0,n=r.length;t<n;++t){var a=r[t];if(a.name===e||a.handler===e){return false}}return true},promise:null,data:null,then:function(e,r,t){return this.promise.then(e,r,t)},"catch":function(e,r){return this.promise["catch"](e,r)},"finally":function(e,r){return this.promise["finally"](e,r)},abort:function(){if(this.isAborted){return this}s(this.router,this.sequence,this.targetName+": transition was aborted");this.intent.preTransitionState=this.router.state;this.isAborted=true;this.isActive=false;this.router.activeTransition=null;return this},retry:function(){this.abort();return this.router.transitionByIntent(this.intent,false)},method:function(e){this.urlMethod=e;return this},trigger:function(e){var r=i.call(arguments);if(typeof e==="boolean"){r.shift()}else{e=false}a(this.router,this.state.handlerInfos.slice(0,this.resolveIndex+1),e,r)},followRedirects:function(){var e=this.router;return this.promise["catch"](function(r){if(e.activeTransition){return e.activeTransition.followRedirects()}return n.reject(r)})},toString:function(){return"Transition (sequence "+this.sequence+")"},log:function(e){s(this.router,this.sequence,e)}};l.prototype.send=l.prototype.trigger;function h(e){s(e.router,e.sequence,"detected abort.");return new f}function f(e){this.message=e||"TransitionAborted";this.name="TransitionAborted"}t.Transition=l;t.logAbort=h;t.TransitionAborted=f});n("router/unrecognized-url-error",["./utils","exports"],function(e,r){"use strict";var t=e.oCreate;function n(e){this.message=e||"UnrecognizedURLError";this.name="UnrecognizedURLError";Error.call(this)}n.prototype=t(Error.prototype);r["default"]=n});n("router/utils",["exports"],function(e){"use strict";var r=Array.prototype.slice;var t;if(!Array.isArray){t=function(e){return Object.prototype.toString.call(e)==="[object Array]"}}else{t=Array.isArray}var n=t;e.isArray=n;function a(e){return(typeof e==="object"&&e!==null||typeof e==="function")&&typeof e.then==="function"}e.isPromise=a;function i(e,r){for(var t in r){if(r.hasOwnProperty(t)){e[t]=r[t]}}}var s=Object.create||function(e){function r(){}r.prototype=e;return new r};e.oCreate=s;function o(e){var t=e&&e.length,n,a;if(t&&t>0&&e[t-1]&&e[t-1].hasOwnProperty("queryParams")){a=e[t-1].queryParams;n=r.call(e,0,t-1);return[n,a]}else{return[e,null]}}e.extractQueryParams=o;function l(e){for(var r in e){if(typeof e[r]==="number"){e[r]=""+e[r]}else if(n(e[r])){for(var t=0,a=e[r].length;t<a;t++){e[r][t]=""+e[r][t]}}}}function u(e,r,t){if(!e.log){return}if(arguments.length===3){e.log("Transition #"+r+": "+t)}else{t=r;e.log(t)}}e.log=u;function h(e,t){var n=arguments;return function(a){var i=r.call(n,2);i.push(a);return t.apply(e,i)}}e.bind=h;function f(e){return typeof e==="string"||e instanceof String||typeof e==="number"||e instanceof Number}function d(e,r){for(var t=0,n=e.length;t<n&&false!==r(e[t]);t++){}}e.forEach=d;function c(e,r,t,n){if(e.triggerEvent){e.triggerEvent(r,t,n);return}var a=n.shift();if(!r){if(t){return}throw new Error("Could not trigger event '"+a+"'. There are no active handlers")}var i=false;function s(e,r,t){t.events[e].apply(t,r)}for(var o=r.length-1;o>=0;o--){var l=r[o],u=l.handler;if(!u){l.handlerPromise.then(h(null,s,a,n));continue}if(u.events&&u.events[a]){if(u.events[a].apply(u,n)===true){i=true}else{return}}}if(a==="error"&&n[0].name==="UnrecognizedURLError"){throw n[0]}else if(!i&&!t){throw new Error("Nothing handled the event '"+a+"'.")}}e.trigger=c;function v(e,r){var t;var a={all:{},changed:{},removed:{}};i(a.all,r);var s=false;l(e);l(r);for(t in e){if(e.hasOwnProperty(t)){if(!r.hasOwnProperty(t)){s=true;a.removed[t]=e[t]}}}for(t in r){if(r.hasOwnProperty(t)){if(n(e[t])&&n(r[t])){if(e[t].length!==r[t].length){a.changed[t]=r[t];s=true}else{for(var o=0,u=e[t].length;o<u;o++){if(e[t][o]!==r[t][o]){a.changed[t]=r[t];s=true}}}}else{if(e[t]!==r[t]){a.changed[t]=r[t];s=true}}}}return s&&a}e.getChangelist=v;function m(e){return"Router: "+e}e.promiseLabel=m;function p(e,r){function t(r){e.call(this,r||{})}t.prototype=s(e.prototype);i(t.prototype,r);return t}e.subclass=p;function g(e,r){if(!e){return}var t="_"+r;return e[t]&&t||e[r]&&r}function y(e,r,t,n){var a=g(e,r);return a&&e[a].call(e,t,n)}function b(e,r,t){var n=g(e,r);if(n){if(t.length===0){return e[n].call(e)}else if(t.length===1){return e[n].call(e,t[0])}else if(t.length===2){return e[n].call(e,t[0],t[1])}else{return e[n].apply(e,t)}}}e.merge=i;e.slice=r;e.isParam=f;e.coerceQueryParamsToString=l;e.callHook=y;e.resolveHook=g;e.applyHook=b});n("router",["./router/router","exports"],function(e,r){"use strict";var t=e["default"];r["default"]=t});n("route-recognizer",[],function(){return{"default":t}});n("rsvp",[],function(){return r});n("rsvp/promise",[],function(){return{"default":r.Promise}});window.Router=a("router")})(window,window.RSVP,window.RouteRecognizer); |
@@ -29,2 +29,3 @@ import RouteRecognizer from 'route-recognizer'; | ||
this.state = undefined; | ||
this.currentSequence = 0; | ||
@@ -63,3 +64,3 @@ this.recognizer = new RouteRecognizer(); | ||
// Create a new transition to the destination route. | ||
newTransition = new Transition(this, intent, newState); | ||
newTransition = new Transition(this, intent, newState, undefined, this.activeTransition); | ||
@@ -630,3 +631,23 @@ // Abort and usurp any previously active transition. | ||
if (urlMethod === 'replace') { | ||
// transitions during the initial transition must always use replaceURL. | ||
// When the app boots, you are at a url, e.g. /foo. If some handler | ||
// redirects to bar as part of the initial transition, you don't want to | ||
// add a history entry for /foo. If you do, pressing back will immediately | ||
// hit the redirect again and take you back to /bar, thus killing the back | ||
// button | ||
var initial = transition.isCausedByInitialTransition; | ||
// say you are at / and you click a link to route /foo. In /foo's | ||
// handler, the transition is aborted using replacewith('/bar'). | ||
// Because the current url is still /, the history entry for / is | ||
// removed from the history. Clicking back will take you to the page | ||
// you were on before /, which is often not even the app, thus killing | ||
// the back button. That's why updateURL is always correct for an | ||
// aborting transition that's not the initial transition | ||
var replaceAndNotAborting = ( | ||
urlMethod === 'replace' && | ||
!transition.isCausedByAbortingTransition | ||
); | ||
if (initial || replaceAndNotAborting) { | ||
router.replaceURL(url); | ||
@@ -633,0 +654,0 @@ } else { |
@@ -19,3 +19,3 @@ import Promise from 'rsvp/promise'; | ||
*/ | ||
function Transition(router, intent, state, error) { | ||
function Transition(router, intent, state, error, previousTransition) { | ||
var transition = this; | ||
@@ -44,2 +44,14 @@ this.state = state || router.state; | ||
// if you're doing multiple redirects, need the new transition to know if it | ||
// is actually part of the first transition or not. Any further redirects | ||
// in the initial transition also need to know if they are part of the | ||
// initial transition | ||
this.isCausedByAbortingTransition = !!previousTransition; | ||
this.isCausedByInitialTransition = ( | ||
previousTransition && ( | ||
previousTransition.isCausedByInitialTransition || | ||
previousTransition.sequence === 0 | ||
) | ||
); | ||
if (state) { | ||
@@ -63,12 +75,5 @@ this.params = state.params; | ||
this.sequence = Transition.currentSequence++; | ||
this.promise = state.resolve(checkForAbort, this)['catch'](function(result) { | ||
if (result.wasAborted || transition.isAborted) { | ||
return Promise.reject(logAbort(transition)); | ||
} else { | ||
transition.trigger('error', result.error, transition, result.handlerWithError); | ||
transition.abort(); | ||
return Promise.reject(result.error); | ||
} | ||
}, promiseLabel('Handle Abort')); | ||
this.sequence = router.currentSequence++; | ||
this.promise = state.resolve(checkForAbort, this)['catch']( | ||
catchHandlerForTransition(transition), promiseLabel('Handle Abort')); | ||
} else { | ||
@@ -86,4 +91,15 @@ this.promise = Promise.resolve(this.state); | ||
Transition.currentSequence = 0; | ||
function catchHandlerForTransition(transition) { | ||
return function(result) { | ||
if (result.wasAborted || transition.isAborted) { | ||
return Promise.reject(logAbort(transition)); | ||
} else { | ||
transition.trigger('error', result.error, transition, result.handlerWithError); | ||
transition.abort(); | ||
return Promise.reject(result.error); | ||
} | ||
}; | ||
} | ||
Transition.prototype = { | ||
@@ -90,0 +106,0 @@ targetName: null, |
{ | ||
"name": "router_js", | ||
"namespace": "Router", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "A lightweight JavaScript library is built on top of route-recognizer and rsvp.js to provide an API for handling routes", | ||
@@ -6,0 +6,0 @@ "author": "Tilde, Inc.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1357135
34936