Skip to content

Commit 649db16

Browse files
fix(TransitionHook): Run all onBefore hooks, even if any hooks return a rejection.
1 parent 3641c2c commit 649db16

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/transition/transition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class Transition implements IHookRegistry {
165165
* @param state (optional) the state in the topath which should receive the new resolves (otherwise, the root state)
166166
*/
167167
addResolves(resolves: IResolveDeclarations, state: IStateOrName = "") {
168-
let stateName = <string> (<any> state).name ? (<any> state).name : state;
168+
let stateName: string = (typeof state === "string") ? state : state.name;
169169
let topath = this._treeChanges.to;
170170
let targetNode = find(topath, node => node.state.name === stateName);
171171
tail(topath).resolveContext.addResolvables(Resolvable.makeResolvables(resolves), targetNode.state);

src/transition/transitionHook.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ export default class TransitionHook {
9191
let results = [];
9292
for (let i = 0; i < hooks.length; i++) {
9393
try {
94-
let hookResult = hooks[i].invokeStep(locals);
95-
let rejection = TransitionHook.isRejection(hookResult);
96-
if (rejection) return rejection;
97-
results.push(hookResult);
94+
results.push(hooks[i].invokeStep(locals));
9895
} catch (exception) {
9996
if (!swallowExceptions) throw exception;
10097
console.log("Swallowed exception during synchronous hook handler: " + exception); // TODO: What to do here?
10198
}
10299
}
103100

104-
return results.filter(<Predicate<any>> isPromise).reduce((chain, promise) => chain.then(val(promise)), runtime.$q.when());
101+
let rejections = results.filter(TransitionHook.isRejection);
102+
if (rejections.length) return rejections[0];
103+
104+
return results
105+
.filter(not(TransitionHook.isRejection))
106+
.filter(<Predicate<any>> isPromise)
107+
.reduce((chain, promise) => chain.then(val(promise)), runtime.$q.when());
105108
}
106109

107110

0 commit comments

Comments
 (0)