-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix validation stage redirection behaviour. #197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { trigger, slice, log, promiseLabel } from './utils'; | |
@param {Object} error | ||
@private | ||
*/ | ||
function Transition(router, intent, state, error) { | ||
function Transition(router, intent, state, error, previousTransition) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must we pass the entire transition forward? It appears that we only need to identify if this is the initial transition. As it stands it seems like this might be closing over a lot of transitions which would keep them dormant in memory longer than we care for. (Need somebody more familiar to confirm/deny, just a quick thought.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The transition isn't needed beyond setting two boolean properties in the constructor. Now my understanding is that because I'm not saving any reference to the transition after the constructor, it will be GC'ed the same place as it was before. Maybe someone with more js VM / GC knowledge can confirm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to agree with @alexspeller here, but might make sense for @stefanpenner / @krisselden / other @tildeio/ember-core folks to sanity check also... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this doesn't affect retention. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexspeller confirm, you aren't retaining it so it does not affect GC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexspeller I spoke too soon, there is a closure to this context being created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reviewing / double checking @krisselden. @nathanhammond - Are you happy to move forward with that confirmation, or should we do more tests (or refactor anyways)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on more detailed review, it looks like I'd likely make a function that took |
||
var transition = this; | ||
this.state = state || router.state; | ||
this.intent = intent; | ||
|
@@ -40,6 +40,18 @@ function Transition(router, intent, state, error) { | |
return; | ||
} | ||
|
||
// 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) { | ||
this.params = state.params; | ||
this.queryParams = state.queryParams; | ||
|
@@ -58,16 +70,9 @@ function Transition(router, intent, state, error) { | |
this.pivotHandler = handlerInfo.handler; | ||
} | ||
|
||
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 { | ||
this.promise = Promise.resolve(this.state); | ||
this.params = {}; | ||
|
@@ -80,7 +85,18 @@ function Transition(router, intent, state, error) { | |
} | ||
} | ||
|
||
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 = { | ||
targetName: null, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to the transition constructor now