Skip to content

Commit e088210

Browse files
chore(trace): add id to viewconfig and viewconfig id to trace
fix(views): Make sure the ViewConfigs get the correct PathNode[] so they can access correct resolve data.
1 parent e9f26f8 commit e088210

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

src/common/trace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function uiViewString (viewData) {
4646

4747
/** @hidden */
4848
const viewConfigString = (viewConfig: ViewConfig) =>
49-
`[ViewConfig from '${viewConfig.viewDecl.$context.name || '(root)'}' state]: target ui-view: '${viewConfig.viewDecl.$uiViewName}@${viewConfig.viewDecl.$uiViewContextAnchor}'`;
49+
`[ViewConfig#${viewConfig.$id} from '${viewConfig.viewDecl.$context.name || '(root)'}' state]: target ui-view: '${viewConfig.viewDecl.$uiViewName}@${viewConfig.viewDecl.$uiViewContextAnchor}'`;
5050

5151
/** @hidden */
5252
function normalizedCat(input: Category): string {

src/ng1/statebuilders/views.ts

+2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ function getComponentInputs($injector, name) {
9999
return cmpDefs.map(getBindings).reduce(unnestR, []);
100100
}
101101

102+
let id = 0;
102103
export class Ng1ViewConfig implements ViewConfig {
104+
$id = id++;
103105
loaded: boolean = false;
104106
controller: Function;
105107
template: string;

src/ng2/statebuilders/views.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export function ng2ViewsBuilder(state: State) {
3636
return views;
3737
}
3838

39+
let id = 0;
3940
export class Ng2ViewConfig implements ViewConfig {
41+
$id: number = id++;
4042
loaded: boolean = true;
4143

4244
constructor(public path: PathNode[], public viewDecl: Ng2ViewDeclaration) { }

src/path/pathFactory.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @module path */ /** for typedoc */
22

3-
import {extend, find, pick, omit, tail, mergeR, values, unnestR, Predicate} from "../common/common";
3+
import {extend, find, pick, omit, tail, mergeR, values, unnestR, Predicate, inArray} from "../common/common";
44
import {prop, propEq, not} from "../common/hof";
55

66
import {RawParams} from "../params/interface";
@@ -11,7 +11,6 @@ import {_ViewDeclaration} from "../state/interface";
1111
import {State} from "../state/stateObject";
1212
import {TargetState} from "../state/targetState";
1313
import {PathNode} from "../path/node";
14-
import {ResolveContext} from "../resolve/resolveContext";
1514
import {ViewService} from "../view/view";
1615

1716
/**
@@ -46,13 +45,13 @@ export class PathFactory {
4645
*
4746
* On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state
4847
*/
49-
static applyViewConfigs($view: ViewService, path: PathNode[]) {
50-
return path.map(node => {
51-
let subPath = PathFactory.subPath(path, n => n === node);
48+
static applyViewConfigs($view: ViewService, path: PathNode[], states: State[]) {
49+
// Only apply the viewConfigs to the nodes for the given states
50+
path.filter(node => inArray(states, node.state)).forEach(node => {
5251
let viewDecls: _ViewDeclaration[] = values(node.state.views || {});
52+
let subPath = PathFactory.subPath(path, n => n === node);
5353
let viewConfigs: ViewConfig[][] = viewDecls.map(view => $view.createViewConfig(subPath, view));
5454
node.views = viewConfigs.reduce(unnestR, []);
55-
return node;
5655
});
5756
}
5857

src/transition/transition.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export class Transition implements IHookRegistry {
150150
this.$id = transitionCount++;
151151
let toPath = PathFactory.buildToPath(fromPath, targetState);
152152
this._treeChanges = PathFactory.treeChanges(fromPath, toPath, this._options.reloadState);
153-
PathFactory.applyViewConfigs(_transitionService.$view, this._treeChanges.to);
153+
let enteringStates = this._treeChanges.entering.map(node => node.state)
154+
PathFactory.applyViewConfigs(_transitionService.$view, this._treeChanges.to, enteringStates);
154155

155156
let rootResolvables: Resolvable[] = [
156157
new Resolvable(Transition, () => this, [], this),

src/view/interface.ts

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface ActiveUIView {
4242
* the `uiViewName` address.
4343
*/
4444
export interface ViewConfig {
45+
/* The unique id for the ViewConfig instance */
46+
$id: number;
4547
/** The normalized view declaration from [[State.views]] */
4648
viewDecl: _ViewDeclaration;
4749

0 commit comments

Comments
 (0)