Skip to content

Commit ba029f6

Browse files
fix(Path): Pre-resolve $stateParams and $transition$ on toPath
fix(HookBuilder): Remove transitionLocals in favor of pre-resolved data on Path
1 parent 6b668f7 commit ba029f6

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/path/pathFactory.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ResolveContext from "../resolve/resolveContext";
1414

1515
import {ViewConfig} from "../view/view";
1616
import ResolveInjector from "../resolve/resolveInjector";
17+
import {Transition} from "../transition/transition";
1718

1819
/**
1920
* This class contains functions which convert TargetStates, Nodes and paths from one type to another.
@@ -92,8 +93,7 @@ export default class PathFactory {
9293
resolvePath.forEach((node: Node) => {
9394
node.resolveContext = resolveContext.isolateRootTo(node.state);
9495
node.resolveInjector = new ResolveInjector(node.resolveContext, node.state);
95-
// node.paramValues = paramValues.$isolateRootTo(node.state.name);
96-
node.resolves["$stateParams"] = new Resolvable("$stateParams", () => node.values, node.state);
96+
node.resolves.$stateParams = new Resolvable("$stateParams", () => node.values, node.state, node.values);
9797
});
9898

9999
return resolvePath;
@@ -138,4 +138,9 @@ export default class PathFactory {
138138

139139
return { from, to, retained, exiting, entering };
140140
}
141+
142+
static bindTransitionResolve(treeChanges: ITreeChanges, transition: Transition) {
143+
let rootNode = treeChanges.to[0];
144+
rootNode.resolves.$transition$ = new Resolvable('$transition$', () => transition, rootNode.state, transition);
145+
}
141146
}

src/resolve/resolvable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import ResolveContext from "./resolveContext"
2222
* parameter to those fns.
2323
*/
2424
export default class Resolvable {
25-
constructor(name: string, resolveFn: Function, state: State) {
25+
constructor(name: string, resolveFn: Function, state: State, preResolvedData?: any) {
2626
this.name = name;
2727
this.resolveFn = resolveFn;
2828
this.state = state;
2929
this.deps = runtime.$injector.annotate(resolveFn);
30+
this.data = preResolvedData;
3031
}
3132

3233
name: string;

src/transition/hookBuilder.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ export default class HookBuilder {
4343
toState: State;
4444
fromState: State;
4545

46-
transitionLocals: { [key: string]: any };
4746

4847
constructor(private $transitions: ITransitionService, private transition: Transition, private baseHookOptions: ITransitionHookOptions) {
4948
this.treeChanges = transition.treeChanges();
5049
this.toState = tail(this.treeChanges.to).state;
5150
this.fromState = tail(this.treeChanges.from).state;
5251
this.transitionOptions = transition.options();
53-
this.transitionLocals = { $transition$: transition };
5452
}
5553

5654
// TODO: These get* methods are returning different cardinalities of hooks
@@ -109,11 +107,9 @@ export default class HookBuilder {
109107
}
110108

111109
/** Given a node and a callback function, builds a TransitionHook */
112-
buildHook(node: Node, fn: IInjectable, moreLocals?, options: ITransitionHookOptions = {}): TransitionHook {
113-
let locals = extend({}, this.transitionLocals, moreLocals);
110+
buildHook(node: Node, fn: IInjectable, locals?, options: ITransitionHookOptions = {}): TransitionHook {
114111
let _options = extend({}, this.baseHookOptions, options);
115-
116-
return new TransitionHook(node.state, fn, locals, node.resolveContext, _options);
112+
return new TransitionHook(node.state, fn, extend({}, locals), node.resolveContext, _options);
117113
}
118114

119115

src/transition/transition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class Transition implements IHookRegistry {
7676
this.$id = transitionCount++;
7777
let toPath = PathFactory.buildToPath(fromPath, targetState);
7878
this._treeChanges = PathFactory.treeChanges(fromPath, toPath, this._options.reloadState);
79+
PathFactory.bindTransitionResolve(this._treeChanges, this);
7980
}
8081

8182
$from() {

0 commit comments

Comments
 (0)