Skip to content

Commit 07fc30c

Browse files
refactor(view): refactor how views are loaded and configured.
- 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
1 parent c813abf commit 07fc30c

29 files changed

+839
-461
lines changed

src/common/common.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,8 @@ export function padString(length: number, str: string) {
499499
return str;
500500
}
501501

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

src/common/trace.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {isNull, isPromise, isNumber, isInjectable, isDefined} from "../common/pr
55
import {Resolvable} from "../resolve/resolvable";
66
import {Transition} from "../transition/transition";
77
import {TransitionRejection} from "../transition/rejectFactory";
8-
import {UIViewData} from "../view/interface";
9-
import {ViewConfig} from "../view/view";
8+
import {ActiveUIView, ViewConfig} from "../view/interface";
109

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

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

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

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

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

181-
traceUiViewConfigUpdated(viewData: UIViewData, context) {
182+
traceUiViewConfigUpdated(viewData: ActiveUIView, context) {
182183
if (!this.enabled(Category.UIVIEW)) return;
183184
this.traceUiViewEvent("Updating", viewData, ` with ViewConfig from context='${context}'`);
184185
}
185186

186-
traceUiViewScopeCreated(viewData: UIViewData, newScope) {
187+
traceUiViewScopeCreated(viewData: ActiveUIView, newScope) {
187188
if (!this.enabled(Category.UIVIEW)) return;
188189
this.traceUiViewEvent("Created scope for", viewData, `, scope #${newScope.$id}`);
189190
}
190191

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

201-
traceViewServiceUiViewEvent(event: string, viewData: UIViewData) {
202+
traceViewServiceUiViewEvent(event: string, viewData: ActiveUIView) {
202203
if (!this.enabled(Category.VIEWCONFIG)) return;
203204
console.log(`$view.ViewConfig: ${event} ${uiViewString(viewData)}`);
204205
}

src/ng1.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ export * from "./ng1/stateDirectives";
1212
export * from "./ng1/stateFilters";
1313
export * from "./ng1/viewDirective";
1414
export * from "./ng1/viewScroll";
15+
export * from "./ng1/viewsBuilder";
1516

1617
export default "ui.router";

0 commit comments

Comments
 (0)