Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resolve: function(shouldContinue, payload) {
// A ResolvedHandlerInfo just resolved with itself.
if (payload && payload.resolvedModels) {
payload.resolvedModels[this.name] = this.context;
}
return Promise.resolve(this, this.promiseLabel("Resolve"));
},
checkForAbort: function(shouldContinue, promiseValue) {
return Promise.resolve(shouldContinue(), this.promiseLabel("Check for abort")).then(function() {
// We don't care about shouldContinue's resolve value;
// pass along the original value passed to this fn.
return promiseValue;
}, null, this.promiseLabel("Ignore fulfillment value and continue"));
},
resolve: function(shouldContinue, payload) {
// First, calculate params for this state. This is useful
// information to provide to the various route hooks.
var params = this.params;
forEach(this.handlerInfos, function(handlerInfo) {
params[handlerInfo.name] = handlerInfo.params || {};
});
payload = payload || {};
payload.resolveIndex = 0;
var currentState = this;
var wasAborted = false;
// The prelude RSVP.resolve() asyncs us into the promise land.
return Promise.resolve(null, this.promiseLabel("Start transition"))
.then(resolveOneHandlerInfo, null, this.promiseLabel('Resolve handler'))['catch'](handleError, this.promiseLabel('Handle error'));
function innerShouldContinue() {
return Promise.resolve(shouldContinue(), currentState.promiseLabel("Check if should continue"))['catch'](function(reason) {
// We distinguish between errors that occurred
// during resolution (e.g. beforeModel/model/afterModel),
// and aborts due to a rejecting promise from shouldContinue().
wasAborted = true;
return Promise.reject(reason);
}, currentState.promiseLabel("Handle abort"));
}
function handleError(error) {
// This is the only possible
// reject value of TransitionState#resolve
var handlerInfos = currentState.handlerInfos;
resolve: function(shouldContinue, payload) {
var checkForAbort = bind(this, this.checkForAbort, shouldContinue),
beforeModel = bind(this, this.runBeforeModelHook, payload),
model = bind(this, this.getModel, payload),
afterModel = bind(this, this.runAfterModelHook, payload),
becomeResolved = bind(this, this.becomeResolved, payload),
self = this;
return Promise.resolve(this.handlerPromise, this.promiseLabel("Start handler"))
.then(function(handler) {
// We nest this chain in case the handlerPromise has an error so that
// we don't have to bubble it through every step
return Promise.resolve(handler)
.then(checkForAbort, null, self.promiseLabel("Check for abort"))
.then(beforeModel, null, self.promiseLabel("Before model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted during 'beforeModel' hook"))
.then(model, null, self.promiseLabel("Model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted in 'model' hook"))
.then(afterModel, null, self.promiseLabel("After model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted in 'afterModel' hook"))
.then(becomeResolved, null, self.promiseLabel("Become resolved"));
}, function(error) {
throw error;
});
},
function innerShouldContinue() {
return Promise.resolve(shouldContinue(), currentState.promiseLabel("Check if should continue"))['catch'](function(reason) {
// We distinguish between errors that occurred
// during resolution (e.g. beforeModel/model/afterModel),
// and aborts due to a rejecting promise from shouldContinue().
wasAborted = true;
return Promise.reject(reason);
}, currentState.promiseLabel("Handle abort"));
}
fetchHandler: function() {
var handler = this.getHandler(this.name);
// Setup a handlerPromise so that we can wait for asynchronously loaded handlers
this.handlerPromise = Promise.resolve(handler);
// Wait until the 'handler' property has been updated when chaining to a handler
// that is a promise
if (isPromise(handler)) {
this.handlerPromise = this.handlerPromise.then(bind(this, this.updateHandler));
} else if (handler) {
// Store the name of the handler on the handler for easy checks later
handler._handlerName = this.name;
return this.handler = handler;
}
return this.handler = undefined;
},
.then(function(handler) {
// We nest this chain in case the handlerPromise has an error so that
// we don't have to bubble it through every step
return Promise.resolve(handler)
.then(checkForAbort, null, self.promiseLabel("Check for abort"))
.then(beforeModel, null, self.promiseLabel("Before model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted during 'beforeModel' hook"))
.then(model, null, self.promiseLabel("Model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted in 'model' hook"))
.then(afterModel, null, self.promiseLabel("After model"))
.then(checkForAbort, null, self.promiseLabel("Check if aborted in 'afterModel' hook"))
.then(becomeResolved, null, self.promiseLabel("Become resolved"));
}, function(error) {
throw error;
function HandlerInfo(_props) {
var props = _props || {};
// Set a default handler to ensure consistent object shape
this._handler = DEFAULT_HANDLER;
if (props.handler) {
var name = props.name;
// Setup a handlerPromise so that we can wait for asynchronously loaded handlers
this.handlerPromise = Promise.resolve(props.handler);
// Wait until the 'handler' property has been updated when chaining to a handler
// that is a promise
if (isPromise(props.handler)) {
this.handlerPromise = this.handlerPromise.then(bind(this, this.updateHandler));
props.handler = undefined;
} else if (props.handler) {
// Store the name of the handler on the handler for easy checks later
props.handler._handlerName = name;
}
}
merge(this, props);
this.initialize(props);
}
getModel: function(payload) {
this.log(payload, this.name + ": resolving provided model");
return Promise.resolve(this.context);
},
runSharedModelHook: function(payload, hookName, args) {
this.log(payload, "calling " + hookName + " hook");
if (this.queryParams) {
args.push(this.queryParams);
}
args.push(payload);
var result = applyHook(this.handler, hookName, args);
if (result && result.isTransition) {
result = null;
}
return Promise.resolve(result, this.promiseLabel("Resolve value returned from one of the model hooks"));
},