Skip to content

Commit b8412da

Browse files
docs(*): organize docs modules; update some docs to typedoc
1 parent 46cdf4c commit b8412da

22 files changed

+481
-134
lines changed

src/common/common.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
/** @module common */ /** for typedoc */
1+
/**
2+
* Random utility functions used in the UI-Router code
3+
*
4+
* @preferred @module common
5+
*/ /** for typedoc */
26

37
import {isFunction, isString, isArray, isRegExp, isDate} from "./predicates";
48
import { all, any, not, prop, curry } from "./hof";

src/common/hof.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Higher order functions
33
*
4-
* @module common
4+
* @module common_hof
55
*/
66

77
/**

src/common/predicates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Predicates @module common */ /** */
1+
/** Predicates @module common_predicates */ /** */
22
import {and, not, pipe, prop} from "./hof";
33

44
const toStr = Object.prototype.toString;

src/common/strings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @module common */ /** */
1+
/** @module common_strings */ /** */
22

33
import {isString, isArray, isDefined, isNull, isPromise, isInjectable, isObject} from "./predicates";
44
import {TransitionRejection} from "../transition/rejectFactory";

src/common/trace.ts

+111-7
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,87 @@
1-
/** @module common */ /** for typedoc */
1+
/**
2+
* UI-Router Transition Tracing
3+
*
4+
* Enable transition tracing to print transition information to the console, in order to help debug your application.
5+
* Tracing logs detailed information about each Transition to your console.
6+
*
7+
* To enable tracing, import the [[trace]] singleton and enable one or more categories.
8+
*
9+
* ES6
10+
* ```
11+
*
12+
* import {trace} from "ui-router-ng2"; // or "angular-ui-router"
13+
* trace.enable(1, 5); // TRANSITION and VIEWCONFIG
14+
* ```
15+
*
16+
* CJS
17+
* ```
18+
*
19+
* let trace = require("angular-ui-router").trace; // or "ui-router-ng2"
20+
* trace.enable("TRANSITION", "VIEWCONFIG");
21+
* ```
22+
*
23+
* Globals
24+
* ```
25+
*
26+
* let trace = window["angular-ui-router"].trace; // or "ui-router-ng2"
27+
* trace.enable(); // Trace everything (very verbose)
28+
* ```
29+
*
30+
* @module trace
31+
*/ /** for typedoc */
232
import {parse} from "../common/hof";
333
import {isNumber} from "../common/predicates";
434
import {Transition} from "../transition/transition";
535
import {ActiveUIView, ViewConfig} from "../view/interface";
636
import {stringify, functionToString, maxLength, padString} from "./strings";
737

38+
/** @hidden */
839
function uiViewString (viewData) {
940
if (!viewData) return 'ui-view (defunct)';
1041
return `ui-view id#${viewData.id}, contextual name '${viewData.name}@${viewData.creationContext}', fqn: '${viewData.fqn}'`;
1142
}
1243

44+
/** @hidden */
1345
const viewConfigString = (viewConfig: ViewConfig) =>
1446
`ViewConfig targeting ui-view: '${viewConfig.viewDecl.$uiViewName}@${viewConfig.viewDecl.$uiViewContextAnchor}', context: '${viewConfig.viewDecl.$context.name}'`;
1547

48+
/** @hidden */
1649
function normalizedCat(input: Category): string {
1750
return isNumber(input) ? Category[input] : Category[Category[input]];
1851
}
1952

2053

54+
/**
55+
* Trace categories
56+
*
57+
* [[Trace.enable]] or [[Trace.disable]] a category
58+
*
59+
* `trace.enable(Category.TRANSITION)`
60+
*
61+
* These can also be provided using a matching string, or position ordinal
62+
*
63+
* `trace.enable("TRANSITION")`
64+
*
65+
* `trace.enable(1)`
66+
*/
2167
export enum Category {
2268
RESOLVE, TRANSITION, HOOK, INVOKE, UIVIEW, VIEWCONFIG
2369
}
2470

71+
/**
72+
* Prints UI-Router Transition trace information to the console.
73+
*/
2574
export class Trace {
2675
approximateDigests: number;
2776

2877
constructor() {
2978
this.approximateDigests = 0;
3079
}
3180

81+
/** @hidden */
3282
private _enabled: { [key: string]: boolean } = {};
3383

84+
/** @hidden */
3485
private _set(enabled: boolean, categories: Category[]) {
3586
if (!categories.length) {
3687
categories = Object.keys(Category)
@@ -40,16 +91,43 @@ export class Trace {
4091
categories.map(normalizedCat).forEach(category => this._enabled[category] = enabled);
4192
}
4293

43-
// TODO: Document enable(categories)
44-
enable = (...categories: Category[]) => this._set(true, categories);
45-
// TODO: Document disable(categories)
46-
disable = (...categories: Category[]) => this._set(false, categories);
94+
/**
95+
* Enables a trace [[Category]]
96+
*
97+
* ```
98+
* trace.enable("TRANSITION");
99+
* ```
100+
*
101+
* @param categories categories to enable. If `categories` is omitted, all categories are enabled.
102+
* Also takes strings (category name) or ordinal (category position)
103+
*/
104+
enable(...categories: Category[]) { this._set(true, categories) }
105+
/**
106+
* Disables a trace [[Category]]
107+
*
108+
* ```
109+
* trace.disable("VIEWCONFIG");
110+
* ```
111+
*
112+
* @param categories categories to disable. If `categories` is omitted, all categories are disabled.
113+
* Also takes strings (category name) or ordinal (category position)
114+
*/
115+
disable(...categories: Category[]) { this._set(false, categories) }
47116

48-
// TODO: Document enabled(category)
49-
enabled(category: Category) {
117+
/**
118+
* Retrieves the enabled stateus of a [[Category]]
119+
*
120+
* ```
121+
* trace.enabled("VIEWCONFIG"); // true or false
122+
* ```
123+
*
124+
* @returns boolean true if the category is enabled
125+
*/
126+
enabled(category: Category): boolean {
50127
return !!this._enabled[normalizedCat(category)];
51128
}
52129

130+
/** called by ui-router code */
53131
traceTransitionStart(transition: Transition) {
54132
if (!this.enabled(Category.TRANSITION)) return;
55133
let tid = transition.$id,
@@ -58,6 +136,7 @@ export class Trace {
58136
console.log(`Transition #${tid} Digest #${digest}: Started -> ${transitionStr}`);
59137
}
60138

139+
/** called by ui-router code */
61140
traceTransitionIgnored(transition: Transition) {
62141
if (!this.enabled(Category.TRANSITION)) return;
63142
let tid = transition.$id,
@@ -66,6 +145,7 @@ export class Trace {
66145
console.log(`Transition #${tid} Digest #${digest}: Ignored <> ${transitionStr}`);
67146
}
68147

148+
/** called by ui-router code */
69149
traceHookInvocation(step, options) {
70150
if (!this.enabled(Category.HOOK)) return;
71151
let tid = parse("transition.$id")(options),
@@ -76,6 +156,7 @@ export class Trace {
76156
console.log(`Transition #${tid} Digest #${digest}: Hook -> ${event} context: ${context}, ${maxLength(200, name)}`);
77157
}
78158

159+
/** called by ui-router code */
79160
traceHookResult(hookResult, transitionResult, transitionOptions) {
80161
if (!this.enabled(Category.HOOK)) return;
81162
let tid = parse("transition.$id")(transitionOptions),
@@ -85,6 +166,7 @@ export class Trace {
85166
console.log(`Transition #${tid} Digest #${digest}: <- Hook returned: ${maxLength(200, hookResultStr)}, transition result: ${maxLength(200, transitionResultStr)}`);
86167
}
87168

169+
/** called by ui-router code */
88170
traceResolvePath(path, options) {
89171
if (!this.enabled(Category.RESOLVE)) return;
90172
let tid = parse("transition.$id")(options),
@@ -94,6 +176,7 @@ export class Trace {
94176
console.log(`Transition #${tid} Digest #${digest}: Resolving ${pathStr} (${policyStr})`);
95177
}
96178

179+
/** called by ui-router code */
97180
traceResolvePathElement(pathElement, resolvablePromises, options) {
98181
if (!this.enabled(Category.RESOLVE)) return;
99182
if (!resolvablePromises.length) return;
@@ -105,6 +188,7 @@ export class Trace {
105188
console.log(`Transition #${tid} Digest #${digest}: Resolve ${pathElementStr} resolvables: [${resolvablePromisesStr}] (${policyStr})`);
106189
}
107190

191+
/** called by ui-router code */
108192
traceResolveResolvable(resolvable, options) {
109193
if (!this.enabled(Category.RESOLVE)) return;
110194
let tid = parse("transition.$id")(options),
@@ -113,6 +197,7 @@ export class Trace {
113197
console.log(`Transition #${tid} Digest #${digest}: Resolving -> ${resolvableStr}`);
114198
}
115199

200+
/** called by ui-router code */
116201
traceResolvableResolved(resolvable, options) {
117202
if (!this.enabled(Category.RESOLVE)) return;
118203
let tid = parse("transition.$id")(options),
@@ -122,6 +207,7 @@ export class Trace {
122207
console.log(`Transition #${tid} Digest #${digest}: <- Resolved ${resolvableStr} to: ${maxLength(200, result)}`);
123208
}
124209

210+
/** called by ui-router code */
125211
tracePathElementInvoke(node, fn, deps, options) {
126212
if (!this.enabled(Category.INVOKE)) return;
127213
let tid = parse("transition.$id")(options),
@@ -131,6 +217,7 @@ export class Trace {
131217
console.log(`Transition #${tid} Digest #${digest}: Invoke ${options.when}: context: ${stateName} ${maxLength(200, fnName)}`);
132218
}
133219

220+
/** called by ui-router code */
134221
traceError(error, transition: Transition) {
135222
if (!this.enabled(Category.TRANSITION)) return;
136223
let tid = transition.$id,
@@ -139,6 +226,7 @@ export class Trace {
139226
console.log(`Transition #${tid} Digest #${digest}: <- Rejected ${transitionStr}, reason: ${error}`);
140227
}
141228

229+
/** called by ui-router code */
142230
traceSuccess(finalState, transition: Transition) {
143231
if (!this.enabled(Category.TRANSITION)) return;
144232
let tid = transition.$id,
@@ -148,36 +236,52 @@ export class Trace {
148236
console.log(`Transition #${tid} Digest #${digest}: <- Success ${transitionStr}, final state: ${state}`);
149237
}
150238

239+
/** called by ui-router code */
151240
traceUiViewEvent(event: string, viewData: ActiveUIView, extra = "") {
152241
if (!this.enabled(Category.UIVIEW)) return;
153242
console.log(`ui-view: ${padString(30, event)} ${uiViewString(viewData)}${extra}`);
154243
}
155244

245+
/** called by ui-router code */
156246
traceUiViewConfigUpdated(viewData: ActiveUIView, context) {
157247
if (!this.enabled(Category.UIVIEW)) return;
158248
this.traceUiViewEvent("Updating", viewData, ` with ViewConfig from context='${context}'`);
159249
}
160250

251+
/** called by ui-router code */
161252
traceUiViewScopeCreated(viewData: ActiveUIView, newScope) {
162253
if (!this.enabled(Category.UIVIEW)) return;
163254
this.traceUiViewEvent("Created scope for", viewData, `, scope #${newScope.$id}`);
164255
}
165256

257+
/** called by ui-router code */
166258
traceUiViewFill(viewData: ActiveUIView, html) {
167259
if (!this.enabled(Category.UIVIEW)) return;
168260
this.traceUiViewEvent("Fill", viewData, ` with: ${maxLength(200, html)}`);
169261
}
170262

263+
/** called by ui-router code */
171264
traceViewServiceEvent(event: string, viewConfig: ViewConfig) {
172265
if (!this.enabled(Category.VIEWCONFIG)) return;
173266
console.log(`$view.ViewConfig: ${event} ${viewConfigString(viewConfig)}`);
174267
}
175268

269+
/** called by ui-router code */
176270
traceViewServiceUiViewEvent(event: string, viewData: ActiveUIView) {
177271
if (!this.enabled(Category.VIEWCONFIG)) return;
178272
console.log(`$view.ViewConfig: ${event} ${uiViewString(viewData)}`);
179273
}
180274
}
181275

276+
/**
277+
* The [[Trace]] singleton
278+
*
279+
* @example
280+
* ```js
281+
*
282+
* import {trace} from "angular-ui-router";
283+
* trace.enable(1, 5);
284+
* ```
285+
*/
182286
let trace = new Trace();
183287
export {trace};

src/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @module core */ /** */
1+
/** @module common */ /** */
22

33
export * from "./common/module";
44
export * from "./params/module";

src/globals.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @module common */ /** */
1+
/** @module core */ /** */
22
import {StateParams} from "./params/stateParams";
33
import {StateDeclaration} from "./state/interface";
44
import {State} from "./state/stateObject";
@@ -9,6 +9,9 @@ import {copy} from "./common/common";
99

1010
/**
1111
* Global mutable state
12+
*
13+
* This is where we hold the global mutable state such as current state, current
14+
* params, current transition, last successful transition, last attempted transition, etc.
1215
*/
1316
export class UIRouterGlobals {
1417
/**

src/ng1/interface.ts

+43
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ import {Transition} from "../transition/transition";
2626
* }
2727
* }
2828
* ```
29+
*
30+
* Since this interface extends [[Ng1ViewDeclaration]], any view declaration properties can be set directly
31+
* on the state declaration and they will be applied to the view with the name `$default`. For example:
32+
*
33+
* ```js
34+
* var state = {
35+
* name: 'foo',
36+
* url: '/foo',
37+
* template: '<h1>foo</h1>',
38+
* controller: 'FooController'
39+
* }
40+
* ```
41+
*
42+
* is simply syntactic sugar for:
43+
*
44+
* ```js
45+
* var state = {
46+
* name: 'foo',
47+
* url: '/foo',
48+
* views: {
49+
* $default: {
50+
* template: '<h1>foo</h1>',
51+
* controller: 'FooController
52+
* }
53+
* }
54+
* }
55+
* ```
56+
*
57+
* If a state definition contains a `views:` object, any view properties set directly on the state are ignored.
58+
* Thus, this is an invalid state defintion:
59+
*
60+
* ```js
61+
* var state = {
62+
* name: 'foo',
63+
* url: '/foo',
64+
* controller: 'FooController, // invalid because views: exists
65+
* views: {
66+
* header: {
67+
* template: '<h1>header</h1>'
68+
* }
69+
* }
70+
* }
71+
* ```
2972
*/
3073
export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaration {
3174
/**

src/ng1/services.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Angular 1 plugin:
2+
* # UI-Router for Angular 1
33
*
44
* - Provides an implementation for the [[CoreServices]] API, based on angular 1 services.
55
* - Also registers some services with the angular 1 injector.

0 commit comments

Comments
 (0)