-
Notifications
You must be signed in to change notification settings - Fork 59
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
Run only required synchronous onBefore
hooks
#2
Conversation
I added tests to make sure I did not break |
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.
Really great PR, thanks so much! I offered a couple of minor suggestions
* Run all TransitionHooks, ignoring their return value. | ||
*/ | ||
static runAllHooks(hooks: TransitionHook[]): void { | ||
hooks.map(hook => { |
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.
Can you change this to forEach
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.
Yeah, makes sense. Fixed.
errorHandler(exception); | ||
// Break on first thrown error or false/TargetState | ||
if (Rejection.isTransitionRejectionPromise(hookResult)) { | ||
return hookResult; |
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.
I think this block could read a little nicer like so:
for (let hook of hooks) {
try {
let hookResult = hook.invokeHook();
if (Rejection.isTransitionRejectionPromise(hookResult)) {
// Break on first thrown error or false/TargetState
return hookResult;
}
results.push(hookResult);
} catch (exception) {
return Rejection.errored(exception).toPromise();
}
}
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.
I thought it improved from before, but this is even nicer. No need to check for TransitionRejection
for known errors. Fixed.
@@ -317,7 +372,9 @@ describe('transition', function () { | |||
.then(done); | |||
})); | |||
|
|||
it('should be called even if other .onSuccess() callbacks fail (throw errors, etc)', ((done) => { | |||
it('should call all .onSuccess() even when callbacks fail (throw errors, etc)', ((done) => { |
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.
lovely, thanks for adding these tests
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.
I was worried about breaking existing functionality, so I thought it best to make sure :)
@@ -364,6 +421,33 @@ describe('transition', function () { | |||
.then(() => expect(hooks).toEqual([ 'splatsplat', 'AD' ])) | |||
.then(done); | |||
})); | |||
|
|||
it('should call all error handlers when transition fails.', ((done) => { |
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.
👍
first hook that modifies the transition. updated request changes
This pull request aims to solve the issue discussed in angular-ui/ui-router#3091