Skip to content

Commit

Permalink
chore(trace): add id to viewconfig and viewconfig id to trace
Browse files Browse the repository at this point in the history
fix(views): Make sure the ViewConfigs get the correct PathNode[] so they can access correct resolve data.
  • Loading branch information
christopherthielen committed Jun 20, 2016
1 parent e9f26f8 commit e088210
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function uiViewString (viewData) {

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

/** @hidden */
function normalizedCat(input: Category): string {
Expand Down
2 changes: 2 additions & 0 deletions src/ng1/statebuilders/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ function getComponentInputs($injector, name) {
return cmpDefs.map(getBindings).reduce(unnestR, []);
}

let id = 0;
export class Ng1ViewConfig implements ViewConfig {
$id = id++;
loaded: boolean = false;
controller: Function;
template: string;
Expand Down
2 changes: 2 additions & 0 deletions src/ng2/statebuilders/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function ng2ViewsBuilder(state: State) {
return views;
}

let id = 0;
export class Ng2ViewConfig implements ViewConfig {
$id: number = id++;
loaded: boolean = true;

constructor(public path: PathNode[], public viewDecl: Ng2ViewDeclaration) { }
Expand Down
11 changes: 5 additions & 6 deletions src/path/pathFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module path */ /** for typedoc */

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

import {RawParams} from "../params/interface";
Expand All @@ -11,7 +11,6 @@ import {_ViewDeclaration} from "../state/interface";
import {State} from "../state/stateObject";
import {TargetState} from "../state/targetState";
import {PathNode} from "../path/node";
import {ResolveContext} from "../resolve/resolveContext";
import {ViewService} from "../view/view";

/**
Expand Down Expand Up @@ -46,13 +45,13 @@ export class PathFactory {
*
* On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state
*/
static applyViewConfigs($view: ViewService, path: PathNode[]) {
return path.map(node => {
let subPath = PathFactory.subPath(path, n => n === node);
static applyViewConfigs($view: ViewService, path: PathNode[], states: State[]) {
// Only apply the viewConfigs to the nodes for the given states
path.filter(node => inArray(states, node.state)).forEach(node => {
let viewDecls: _ViewDeclaration[] = values(node.state.views || {});
let subPath = PathFactory.subPath(path, n => n === node);
let viewConfigs: ViewConfig[][] = viewDecls.map(view => $view.createViewConfig(subPath, view));
node.views = viewConfigs.reduce(unnestR, []);
return node;
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/transition/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export class Transition implements IHookRegistry {
this.$id = transitionCount++;
let toPath = PathFactory.buildToPath(fromPath, targetState);
this._treeChanges = PathFactory.treeChanges(fromPath, toPath, this._options.reloadState);
PathFactory.applyViewConfigs(_transitionService.$view, this._treeChanges.to);
let enteringStates = this._treeChanges.entering.map(node => node.state)
PathFactory.applyViewConfigs(_transitionService.$view, this._treeChanges.to, enteringStates);

let rootResolvables: Resolvable[] = [
new Resolvable(Transition, () => this, [], this),
Expand Down
2 changes: 2 additions & 0 deletions src/view/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface ActiveUIView {
* the `uiViewName` address.
*/
export interface ViewConfig {
/* The unique id for the ViewConfig instance */
$id: number;
/** The normalized view declaration from [[State.views]] */
viewDecl: _ViewDeclaration;

Expand Down

0 comments on commit e088210

Please sign in to comment.