Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created April 30, 2014 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppcano/1587da78e8496933ff1e to your computer and use it in GitHub Desktop.
Save ppcano/1587da78e8496933ff1e to your computer and use it in GitHub Desktop.
Rewriting HandlerInfo.js
import Promise from 'rsvp/promise';
var HandlerInfo = requireModule("router/handler-info")['HandlerInfo'];
var bind = requireModule("router/utils").bind;
HandlerInfo.prototype.resolve = function(async, shouldContinue, payload) {
var checkForAbort = bind(this.checkForAbort, this, shouldContinue),
beforeModel = bind(this.runBeforeModelHook, this, async, payload),
model = bind(this.getModel, this, async, payload),
afterModel = bind(this.runAfterModelHook, this, async, payload),
animation = bind(this.runAnimationHook, this, async, payload),
becomeResolved = bind(this.becomeResolved, this, payload);
return Promise.resolve(undefined, this.promiseLabel("Start handler"))
.then(checkForAbort, null, this.promiseLabel("Check for abort"))
.then(beforeModel, null, this.promiseLabel("Before model"))
.then(checkForAbort, null, this.promiseLabel("Check if aborted during 'beforeModel' hook"))
.then(model, null, this.promiseLabel("Model"))
.then(checkForAbort, null, this.promiseLabel("Check if aborted in 'model' hook"))
.then(afterModel, null, this.promiseLabel("After model"))
.then(checkForAbort, null, this.promiseLabel("Check if aborted in 'afterModel' hook"))
.then(animation, null, this.promiseLabel("Animation"))
.then(checkForAbort, null, this.promiseLabel("Check if aborted in 'animation' hook"))
.then(becomeResolved, null, this.promiseLabel("Become resolved"));
};
HandlerInfo.prototype.runAnimationHook = function(async, payload, promiseValue) {
var handler = this.handler;
return async(function() {
return handler.animation && handler.animation.apply(handler, [payload]);
}, this.promiseLabel("Handle Animation")).then(function() {
return promiseValue;
}, null, this.promiseLabel("Ignore animation value and return model value"));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment