diff --git a/src/transition/hookBuilder.ts b/src/transition/hookBuilder.ts index d680f8537..1c69ebc90 100644 --- a/src/transition/hookBuilder.ts +++ b/src/transition/hookBuilder.ts @@ -98,8 +98,7 @@ export class HookBuilder { return matchingNodes.map(node => { let _options = extend({ bind: hook.bind, traceData: { hookType, context: node} }, this.baseHookOptions, options); let state = _options.stateHook ? node.state : null; - let context = resolveContext.subContext(node.state); - let transitionHook = new TransitionHook(this.transition, state, hook.callback, context, _options); + let transitionHook = new TransitionHook(this.transition, state, hook.callback, _options); return { hook, node, transitionHook }; }); }; diff --git a/src/transition/transitionHook.ts b/src/transition/transitionHook.ts index d57433f2b..a16c691ad 100644 --- a/src/transition/transitionHook.ts +++ b/src/transition/transitionHook.ts @@ -1,6 +1,6 @@ /** @module transition */ /** for typedoc */ -import {TransitionHookOptions, TransitionStateHookFn, HookFn, TransitionHookFn} from "./interface"; -import {defaults, noop, Predicate} from "../common/common"; +import {TransitionHookOptions, HookFn, HookResult} from "./interface"; +import {defaults, noop} from "../common/common"; import {fnToString, maxLength} from "../common/strings"; import {isDefined, isPromise } from "../common/predicates"; import {pattern, val, eq, is, parse } from "../common/hof"; @@ -27,15 +27,14 @@ export class TransitionHook { constructor(private transition: Transition, private stateContext: State, private hookFn: HookFn, - private resolveContext: ResolveContext, private options: TransitionHookOptions) { this.options = defaults(options, defaultOptions); } private isSuperseded = () => this.options.current() !== this.options.transition; - invokeHook(): Promise { - let { options, hookFn, resolveContext } = this; + invokeHook(): Promise { + let { options, hookFn } = this; trace.traceHookInvocation(this, options); if (options.rejectIfSuperseded && this.isSuperseded()) { return Rejection.superseded(options.current()).toPromise(); diff --git a/test/core/hookBuilderSpec.ts b/test/core/hookBuilderSpec.ts index 72c6bc141..1ecd6ee8b 100644 --- a/test/core/hookBuilderSpec.ts +++ b/test/core/hookBuilderSpec.ts @@ -162,18 +162,18 @@ describe('HookBuilder:', function() { Object.keys($trans._deregisterHookFns).forEach(key => $trans._deregisterHookFns[key]()); }); - describe('should be bound to the correct context', function() { + describe('should have the correct state context', function() { const context = hook => - tail(hook.resolveContext['_path']).state.name; + hook.stateContext && hook.stateContext.name; - it('; onBefore should be bound to the to state', function() { + it('; onBefore should not have a state context', function() { trans.onBefore({}, callback); - expect(hb.getOnBeforeHooks().map(context)).toEqual(["A.B.C"]); + expect(hb.getOnBeforeHooks().map(context)).toEqual([null]); }); - it('; onStart should be bound to the to state', function() { + it('; onStart should not have a state context', function() { trans.onStart({}, callback); - expect(hb.getOnStartHooks().map(context)).toEqual(["A.B.C"]); + expect(hb.getOnStartHooks().map(context)).toEqual([null]); }); it('; onEnter should be bound to the entering state(s)', function() { @@ -186,30 +186,25 @@ describe('HookBuilder:', function() { expect(hb.getOnRetainHooks().map(context)).toEqual(["", "A"]); }); - it('; onRetain should be bound to the retained state(s)', function() { - trans.onRetain({}, callback); - expect(hb.getOnRetainHooks().map(context)).toEqual(["", "A"]); - }); - it('; onExit should be bound to the exiting state(s)', function() { trans2.onExit({}, callback); expect(hb2.getOnExitHooks().map(context)).toEqual(["A.B.C", "A.B"]); }); - it('; onFinish should be bound to the to state', function() { + it('; onFinish should not have a state context', function() { trans.onFinish({}, callback); - expect(hb.getOnFinishHooks().map(context)).toEqual(["A.B.C"]); + expect(hb.getOnFinishHooks().map(context)).toEqual([null]); }); - it('; onSuccess should be bound to the to state', function() { + it('; onSuccess should not have a state context', function() { trans.onSuccess({}, callback); - expect(hb.getOnSuccessHooks().map(context)).toEqual(["A.B.C"]); + expect(hb.getOnSuccessHooks().map(context)).toEqual([null]); }); - it('; onError should be bound to the to state', function() { + it('; onError should not have a state context', function() { trans.onStart({}, () => { throw new Error('shuckydarn') }); trans.onError({}, callback); - expect(hb.getOnErrorHooks().map(context)).toEqual(["A.B.C"]); + expect(hb.getOnErrorHooks().map(context)).toEqual([null]); }); });