Skip to content

Commit

Permalink
refactor(view): refactor how views are loaded and configured.
Browse files Browse the repository at this point in the history
- Require a Framework-specific (ng1/ng2) StateBuilder `views` decorator
- The `views` decorator takes `ViewDeclaration`s and returns normalized `ViewDeclaration`s
- Before a `Transition` begins, a `ViewConfig` is created and bound to the appropriate Node
- During the transition, the `ViewConfig` is prepped using `load()`
- After the configs are prepped, they are registered with the `StateService`, to be matched with `ui-view`s
- The `$element.data('$uiView')` is reorganized and simplified.
  - $element.data('$uiView').$uiView has the ActiveUIView object
  - $element.data('$uiView').$cfg has the ViewConfig object
  • Loading branch information
christopherthielen committed Mar 14, 2016
1 parent c813abf commit 07fc30c
Show file tree
Hide file tree
Showing 29 changed files with 839 additions and 461 deletions.
3 changes: 1 addition & 2 deletions src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,8 @@ export function padString(length: number, str: string) {
return str;
}

export function tail<T>(collection: T[]): T;
/** Get the last element of an array */
export function tail(arr: any[]): any {
export function tail<T>(arr: T[]): T {
return arr.length && arr[arr.length - 1] || undefined;
}

Expand Down
21 changes: 11 additions & 10 deletions src/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {isNull, isPromise, isNumber, isInjectable, isDefined} from "../common/pr
import {Resolvable} from "../resolve/resolvable";
import {Transition} from "../transition/transition";
import {TransitionRejection} from "../transition/rejectFactory";
import {UIViewData} from "../view/interface";
import {ViewConfig} from "../view/view";
import {ActiveUIView, ViewConfig} from "../view/interface";

function promiseToString(p) {
if (is(TransitionRejection)(p.reason)) return p.reason.toString();
Expand All @@ -19,11 +18,13 @@ function functionToString(fn) {
return namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
}

const uiViewString = (viewData) =>
`ui-view id#${viewData.id}, contextual name '${viewData.name}@${viewData.creationContext}', fqn: '${viewData.fqn}'`;
function uiViewString (viewData) {
if (!viewData) return 'ui-view (defunct)';
return `ui-view id#${viewData.id}, contextual name '${viewData.name}@${viewData.creationContext}', fqn: '${viewData.fqn}'`;
}

const viewConfigString = (viewConfig: ViewConfig) =>
`ViewConfig targeting ui-view: '${viewConfig.uiViewName}@${viewConfig.uiViewContextAnchor}', context: '${viewConfig.context.name}'`;
`ViewConfig targeting ui-view: '${viewConfig.viewDecl.$uiViewName}@${viewConfig.viewDecl.$uiViewContextAnchor}', context: '${viewConfig.viewDecl.$context.name}'`;

function normalizedCat(input: Category): string {
return isNumber(input) ? Category[input] : Category[Category[input]];
Expand Down Expand Up @@ -173,22 +174,22 @@ export class Trace {
console.log(`Transition #${tid} Digest #${digest}: <- Success ${transitionStr}, final state: ${state}`);
}

traceUiViewEvent(event: string, viewData: UIViewData, extra = "") {
traceUiViewEvent(event: string, viewData: ActiveUIView, extra = "") {
if (!this.enabled(Category.UIVIEW)) return;
console.log(`ui-view: ${padString(30, event)} ${uiViewString(viewData)}${extra}`);
}

traceUiViewConfigUpdated(viewData: UIViewData, context) {
traceUiViewConfigUpdated(viewData: ActiveUIView, context) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Updating", viewData, ` with ViewConfig from context='${context}'`);
}

traceUiViewScopeCreated(viewData: UIViewData, newScope) {
traceUiViewScopeCreated(viewData: ActiveUIView, newScope) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Created scope for", viewData, `, scope #${newScope.$id}`);
}

traceUiViewFill(viewData: UIViewData, html) {
traceUiViewFill(viewData: ActiveUIView, html) {
if (!this.enabled(Category.UIVIEW)) return;
this.traceUiViewEvent("Fill", viewData, ` with: ${maxLength(200, html)}`);
}
Expand All @@ -198,7 +199,7 @@ export class Trace {
console.log(`$view.ViewConfig: ${event} ${viewConfigString(viewConfig)}`);
}

traceViewServiceUiViewEvent(event: string, viewData: UIViewData) {
traceViewServiceUiViewEvent(event: string, viewData: ActiveUIView) {
if (!this.enabled(Category.VIEWCONFIG)) return;
console.log(`$view.ViewConfig: ${event} ${uiViewString(viewData)}`);
}
Expand Down
1 change: 1 addition & 0 deletions src/ng1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export * from "./ng1/stateDirectives";
export * from "./ng1/stateFilters";
export * from "./ng1/viewDirective";
export * from "./ng1/viewScroll";
export * from "./ng1/viewsBuilder";

export default "ui.router";
Loading

0 comments on commit 07fc30c

Please sign in to comment.