@angular-wave/angular.ts 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/e2e/unit.spec.ts +2 -1
- package/index.html +6 -6
- package/package.json +1 -1
- package/src/core/pubsub.js +329 -0
- package/src/router/common/trace.js +6 -6
- package/src/router/directives/state-directives.js +74 -74
- package/src/router/directives/view-directive.js +21 -21
- package/src/router/hooks/core-resolvables.js +12 -11
- package/src/router/hooks/ignored-transition.js +1 -1
- package/src/router/hooks/lazy-load.js +40 -41
- package/src/router/hooks/redirect-to.js +32 -29
- package/src/router/hooks/update-globals.js +1 -1
- package/src/router/hooks/url.js +33 -24
- package/src/router/hooks/views.js +21 -20
- package/src/router/index.js +12 -12
- package/src/router/injectables.js +3 -3
- package/src/router/params/param-factory.js +17 -0
- package/src/router/router.js +75 -10
- package/src/router/services.js +4 -8
- package/src/router/state/state-builder.js +1 -0
- package/src/router/state/state-queue-manager.js +5 -4
- package/src/router/state/state-registry.js +63 -7
- package/src/router/state/state-service.js +47 -51
- package/src/router/state/views.js +4 -4
- package/src/router/state-filters.js +0 -2
- package/src/router/state-provider.js +0 -2
- package/src/router/template-factory.js +4 -4
- package/src/router/transition/hook-builder.js +2 -2
- package/src/router/transition/transition-hook.js +2 -1
- package/src/router/transition/transition-service.js +11 -18
- package/src/router/transition/transition.js +28 -25
- package/src/router/url/url-config.js +1 -49
- package/src/router/url/url-matcher-factory.js +10 -51
- package/src/router/url/url-router.js +31 -17
- package/src/router/url/url-rule.js +9 -13
- package/src/router/url/url-rules.js +3 -3
- package/src/router/url/url-service.js +22 -18
- package/src/router/view/view.js +67 -67
- package/src/services/browser.js +1 -5
- package/src/shared/hof.js +1 -1
- package/test/angular.spec.js +1 -0
- package/test/aria/aria.spec.js +2 -1
- package/test/core/pubsub.spec.js +387 -0
- package/test/directive/bind.spec.js +2 -1
- package/test/directive/boolean.spec.js +4 -2
- package/test/directive/change.spec.js +1 -1
- package/test/directive/class.spec.js +1 -0
- package/test/directive/click.spec.js +2 -1
- package/test/directive/cloak.spec.js +1 -2
- package/test/directive/{constoller.spec.js → controller.spec.js} +1 -0
- package/test/directive/element-style.spec.js +1 -0
- package/test/directive/event.spec.js +1 -1
- package/test/directive/href.spec.js +2 -1
- package/test/directive/init.spec.js +1 -0
- package/test/directive/input.spec.js +200 -285
- package/test/directive/list.spec.js +2 -1
- package/test/directive/model.spec.js +1 -0
- package/test/directive/non-bindable.spec.js +2 -1
- package/test/directive/script.spec.js +1 -0
- package/test/directive/scrset.spec.js +2 -1
- package/test/directive/show-hide.spec.js +1 -0
- package/test/directive/src.spec.js +2 -1
- package/test/directive/style.spec.js +1 -0
- package/test/directive/switch.spec.js +2 -1
- package/test/directive/validators.spec.js +1 -1
- package/test/module-test.html +5 -5
- package/test/original-test.html +3 -3
- package/test/router/services.spec.js +1 -1
- package/test/router/state-directives.spec.js +72 -80
- package/test/router/state-filter.spec.js +6 -4
- package/test/router/state.spec.js +15 -13
- package/test/router/template-factory.spec.js +4 -4
- package/test/router/url-matcher-factory.spec.js +2 -2
- package/test/router/view-directive.spec.js +165 -163
- package/test/router/view-hook.spec.js +4 -4
- package/test/router/view-scroll.spec.js +15 -15
- package/test/router/view.spec.js +3 -3
- package/types/router/core/common/coreservices.d.ts +2 -3
- package/types/router/core/globals.d.ts +1 -4
- package/types/router/core/interface.d.ts +2 -8
- package/types/router/core/params/paramTypes.d.ts +0 -1
- package/types/router/core/router.d.ts +2 -3
- package/types/router/core/state/interface.d.ts +6 -6
- package/types/router/core/state/stateQueueManager.d.ts +1 -3
- package/types/router/core/state/stateRegistry.d.ts +1 -2
- package/types/router/core/state/stateService.d.ts +5 -6
- package/types/router/core/transition/interface.d.ts +4 -4
- package/types/router/core/transition/transitionService.d.ts +1 -2
- package/types/router/core/url/urlConfig.d.ts +1 -2
- package/types/router/core/url/urlRules.d.ts +1 -2
- package/types/router/core/url/urlService.d.ts +1 -2
- package/types/router/core/view/interface.d.ts +2 -2
- package/types/router/core/view/view.d.ts +16 -16
- package/types/router/directives/viewDirective.d.ts +3 -3
- package/types/router/interface.d.ts +4 -4
- package/types/router/locationServices.d.ts +0 -1
- package/types/router/stateProvider.d.ts +3 -3
- package/types/router/statebuilders/views.d.ts +1 -1
- package/types/router/templateFactory.d.ts +2 -2
- package/types/router/viewScroll.d.ts +1 -1
|
@@ -19,27 +19,21 @@ import { Glob } from "../common/glob";
|
|
|
19
19
|
import { ResolveContext } from "../resolve/resolve-context";
|
|
20
20
|
import { lazyLoadState } from "../hooks/lazy-load";
|
|
21
21
|
import { not, val } from "../../shared/hof";
|
|
22
|
+
import { EventBus } from "../../core/pubsub";
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* Provides services related to ui-router states.
|
|
24
26
|
*
|
|
25
27
|
* This API is located at `router.stateService` ([[UIRouter.stateService]])
|
|
26
28
|
*/
|
|
27
29
|
export class StateService {
|
|
28
|
-
/**
|
|
29
|
-
* The [[Transition]] currently in progress (or null)
|
|
30
|
-
*
|
|
31
|
-
* @deprecated This is a passthrough through to [[UIRouterGlobals.transition]]
|
|
32
|
-
*/
|
|
33
|
-
get transition() {
|
|
34
|
-
return this.router.globals.transition;
|
|
35
|
-
}
|
|
36
30
|
/**
|
|
37
31
|
* The latest successful state parameters
|
|
38
32
|
*
|
|
39
33
|
* @deprecated This is a passthrough through to [[UIRouterGlobals.params]]
|
|
40
34
|
*/
|
|
41
35
|
get params() {
|
|
42
|
-
return this.
|
|
36
|
+
return this.globals.params;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* The current [[StateDeclaration]]
|
|
@@ -47,7 +41,7 @@ export class StateService {
|
|
|
47
41
|
* @deprecated This is a passthrough through to [[UIRouterGlobals.current]]
|
|
48
42
|
*/
|
|
49
43
|
get current() {
|
|
50
|
-
return this.
|
|
44
|
+
return this.globals.current;
|
|
51
45
|
}
|
|
52
46
|
/**
|
|
53
47
|
* The current [[StateObject]] (an internal API)
|
|
@@ -55,13 +49,16 @@ export class StateService {
|
|
|
55
49
|
* @deprecated This is a passthrough through to [[UIRouterGlobals.$current]]
|
|
56
50
|
*/
|
|
57
51
|
get $current() {
|
|
58
|
-
return this.
|
|
52
|
+
return this.globals.$current;
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
|
|
55
|
+
// Needs access to urlRouter, stateRegistry
|
|
56
|
+
constructor(globals, transitionService) {
|
|
57
|
+
this.stateRegistry = undefined;
|
|
58
|
+
this.urlRouter = undefined;
|
|
59
|
+
this.urlService = undefined;
|
|
60
|
+
this.globals = globals;
|
|
61
|
+
this.transitionService = transitionService;
|
|
65
62
|
this.invalidCallbacks = [];
|
|
66
63
|
|
|
67
64
|
this._defaultErrorHandler = function $defaultErrorHandler($error$) {
|
|
@@ -83,6 +80,10 @@ export class StateService {
|
|
|
83
80
|
val(this),
|
|
84
81
|
boundFns,
|
|
85
82
|
);
|
|
83
|
+
|
|
84
|
+
EventBus.subscribe("$stateService:defaultErrorHandler", (err) =>
|
|
85
|
+
this.defaultErrorHandler()(err),
|
|
86
|
+
);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/**
|
|
@@ -97,11 +98,8 @@ export class StateService {
|
|
|
97
98
|
* @internal
|
|
98
99
|
*/
|
|
99
100
|
_handleInvalidTargetState(fromPath, toState) {
|
|
100
|
-
const fromState = PathUtils.makeTargetState(
|
|
101
|
-
|
|
102
|
-
fromPath,
|
|
103
|
-
);
|
|
104
|
-
const globals = this.router.globals;
|
|
101
|
+
const fromState = PathUtils.makeTargetState(this.stateRegistry, fromPath);
|
|
102
|
+
const globals = this.globals;
|
|
105
103
|
const latestThing = () => globals.transitionHistory.peekTail();
|
|
106
104
|
const latest = latestThing();
|
|
107
105
|
const callbackQueue = new Queue(this.invalidCallbacks.slice());
|
|
@@ -217,7 +215,7 @@ export class StateService {
|
|
|
217
215
|
* @returns A promise representing the state of the new transition. See [[StateService.go]]
|
|
218
216
|
*/
|
|
219
217
|
reload(reloadState) {
|
|
220
|
-
return this.transitionTo(this.current, this.params, {
|
|
218
|
+
return this.transitionTo(this.globals.current, this.globals.params, {
|
|
221
219
|
reload: isDefined(reloadState) ? reloadState : true,
|
|
222
220
|
inherit: false,
|
|
223
221
|
notify: false,
|
|
@@ -279,7 +277,7 @@ export class StateService {
|
|
|
279
277
|
// If we're reloading, find the state object to reload from
|
|
280
278
|
if (isObject(options.reload) && !options.reload.name)
|
|
281
279
|
throw new Error("Invalid reload state object");
|
|
282
|
-
const reg = this.
|
|
280
|
+
const reg = this.stateRegistry;
|
|
283
281
|
options.reloadState =
|
|
284
282
|
options.reload === true
|
|
285
283
|
? reg.root()
|
|
@@ -288,18 +286,13 @@ export class StateService {
|
|
|
288
286
|
throw new Error(
|
|
289
287
|
`No such reload state '${isString(options.reload) ? options.reload : options.reload.name}'`,
|
|
290
288
|
);
|
|
291
|
-
return new TargetState(
|
|
292
|
-
this.router.stateRegistry,
|
|
293
|
-
identifier,
|
|
294
|
-
params,
|
|
295
|
-
options,
|
|
296
|
-
);
|
|
289
|
+
return new TargetState(this.stateRegistry, identifier, params, options);
|
|
297
290
|
}
|
|
298
291
|
|
|
299
292
|
getCurrentPath() {
|
|
300
|
-
const globals = this.
|
|
293
|
+
const globals = this.globals;
|
|
301
294
|
const latestSuccess = globals.successfulTransitions.peekTail();
|
|
302
|
-
const rootPath = () => [new PathNode(this.
|
|
295
|
+
const rootPath = () => [new PathNode(this.stateRegistry.root())];
|
|
303
296
|
return latestSuccess ? latestSuccess.treeChanges().to : rootPath();
|
|
304
297
|
}
|
|
305
298
|
/**
|
|
@@ -326,10 +319,8 @@ export class StateService {
|
|
|
326
319
|
* @returns A promise representing the state of the new transition. See [[go]]
|
|
327
320
|
*/
|
|
328
321
|
transitionTo(to, toParams = {}, options = {}) {
|
|
329
|
-
const router = this.router;
|
|
330
|
-
const globals = router.globals;
|
|
331
322
|
options = defaults(options, defaultTransOpts);
|
|
332
|
-
const getCurrent = () => globals.transition;
|
|
323
|
+
const getCurrent = () => this.globals.transition;
|
|
333
324
|
options = Object.assign(options, { current: getCurrent });
|
|
334
325
|
const ref = this.target(to, toParams, options);
|
|
335
326
|
const currentPath = this.getCurrentPath();
|
|
@@ -351,11 +342,11 @@ export class StateService {
|
|
|
351
342
|
*/
|
|
352
343
|
const rejectedTransitionHandler = (trans) => (error) => {
|
|
353
344
|
if (error instanceof Rejection) {
|
|
354
|
-
const isLatest =
|
|
345
|
+
const isLatest = this.globals.lastStartedTransitionId <= trans.$id;
|
|
355
346
|
if (error.type === RejectType.IGNORED) {
|
|
356
|
-
isLatest &&
|
|
347
|
+
isLatest && EventBus.publish("urlRouter.update");
|
|
357
348
|
// Consider ignored `Transition.run()` as a successful `transitionTo`
|
|
358
|
-
return services.$q.when(globals.current);
|
|
349
|
+
return services.$q.when(this.globals.current);
|
|
359
350
|
}
|
|
360
351
|
const detail = error.detail;
|
|
361
352
|
if (
|
|
@@ -369,7 +360,7 @@ export class StateService {
|
|
|
369
360
|
return redirect.run().catch(rejectedTransitionHandler(redirect));
|
|
370
361
|
}
|
|
371
362
|
if (error.type === RejectType.ABORTED) {
|
|
372
|
-
isLatest &&
|
|
363
|
+
isLatest && EventBus.publish("urlRouter.update");
|
|
373
364
|
return services.$q.reject(error);
|
|
374
365
|
}
|
|
375
366
|
}
|
|
@@ -377,7 +368,7 @@ export class StateService {
|
|
|
377
368
|
errorHandler(error);
|
|
378
369
|
return services.$q.reject(error);
|
|
379
370
|
};
|
|
380
|
-
const transition = this.
|
|
371
|
+
const transition = this.transitionService.create(currentPath, ref);
|
|
381
372
|
const transitionToPromise = transition
|
|
382
373
|
.run()
|
|
383
374
|
.catch(rejectedTransitionHandler(transition));
|
|
@@ -418,7 +409,7 @@ export class StateService {
|
|
|
418
409
|
*/
|
|
419
410
|
is(stateOrName, params, options) {
|
|
420
411
|
options = defaults(options, { relative: this.$current });
|
|
421
|
-
const state = this.
|
|
412
|
+
const state = this.stateRegistry.matcher.find(
|
|
422
413
|
stateOrName,
|
|
423
414
|
options.relative,
|
|
424
415
|
);
|
|
@@ -426,7 +417,11 @@ export class StateService {
|
|
|
426
417
|
if (this.$current !== state) return false;
|
|
427
418
|
if (!params) return true;
|
|
428
419
|
const schema = state.parameters({ inherit: true, matchingKeys: params });
|
|
429
|
-
return Param.equals(
|
|
420
|
+
return Param.equals(
|
|
421
|
+
schema,
|
|
422
|
+
Param.values(schema, params),
|
|
423
|
+
this.globals.params,
|
|
424
|
+
);
|
|
430
425
|
}
|
|
431
426
|
/**
|
|
432
427
|
* Checks if the current state *includes* the provided state
|
|
@@ -473,7 +468,7 @@ export class StateService {
|
|
|
473
468
|
if (!glob.matches(this.$current.name)) return false;
|
|
474
469
|
stateOrName = this.$current.name;
|
|
475
470
|
}
|
|
476
|
-
const state = this.
|
|
471
|
+
const state = this.stateRegistry.matcher.find(
|
|
477
472
|
stateOrName,
|
|
478
473
|
options.relative,
|
|
479
474
|
),
|
|
@@ -482,7 +477,11 @@ export class StateService {
|
|
|
482
477
|
if (!isDefined(include[state.name])) return false;
|
|
483
478
|
if (!params) return true;
|
|
484
479
|
const schema = state.parameters({ inherit: true, matchingKeys: params });
|
|
485
|
-
return Param.equals(
|
|
480
|
+
return Param.equals(
|
|
481
|
+
schema,
|
|
482
|
+
Param.values(schema, params),
|
|
483
|
+
this.globals.params,
|
|
484
|
+
);
|
|
486
485
|
}
|
|
487
486
|
/**
|
|
488
487
|
* Generates a URL for a state and parameters
|
|
@@ -509,18 +508,18 @@ export class StateService {
|
|
|
509
508
|
};
|
|
510
509
|
options = defaults(options, defaultHrefOpts);
|
|
511
510
|
params = params || {};
|
|
512
|
-
const state = this.
|
|
511
|
+
const state = this.stateRegistry.matcher.find(
|
|
513
512
|
stateOrName,
|
|
514
513
|
options.relative,
|
|
515
514
|
);
|
|
516
515
|
if (!isDefined(state)) return null;
|
|
517
516
|
if (options.inherit)
|
|
518
|
-
params = this.params.$inherit(params, this.$current, state);
|
|
517
|
+
params = this.globals.params.$inherit(params, this.$current, state);
|
|
519
518
|
const nav = state && options.lossy ? state.navigable : state;
|
|
520
519
|
if (!nav || nav.url === undefined || nav.url === null) {
|
|
521
520
|
return null;
|
|
522
521
|
}
|
|
523
|
-
return this.
|
|
522
|
+
return this.urlRouter.href(nav.url, params, {
|
|
524
523
|
absolute: options.absolute,
|
|
525
524
|
});
|
|
526
525
|
}
|
|
@@ -552,7 +551,7 @@ export class StateService {
|
|
|
552
551
|
return (this._defaultErrorHandler = handler || this._defaultErrorHandler);
|
|
553
552
|
}
|
|
554
553
|
get(stateOrName, base) {
|
|
555
|
-
const reg = this.
|
|
554
|
+
const reg = this.stateRegistry;
|
|
556
555
|
if (arguments.length === 0) return reg.get();
|
|
557
556
|
return reg.get(stateOrName, base || this.$current);
|
|
558
557
|
}
|
|
@@ -573,12 +572,9 @@ export class StateService {
|
|
|
573
572
|
if (!state || !state.lazyLoad)
|
|
574
573
|
throw new Error("Can not lazy load " + stateOrName);
|
|
575
574
|
const currentPath = this.getCurrentPath();
|
|
576
|
-
const target = PathUtils.makeTargetState(
|
|
577
|
-
this.router.stateRegistry,
|
|
578
|
-
currentPath,
|
|
579
|
-
);
|
|
575
|
+
const target = PathUtils.makeTargetState(this.stateRegistry, currentPath);
|
|
580
576
|
transition =
|
|
581
|
-
transition || this.
|
|
577
|
+
transition || this.transitionService.create(currentPath, target);
|
|
582
578
|
return lazyLoadState(transition, state);
|
|
583
579
|
}
|
|
584
580
|
}
|
|
@@ -81,8 +81,8 @@ export function ng1ViewsBuilder(state) {
|
|
|
81
81
|
config.$context,
|
|
82
82
|
config.$name,
|
|
83
83
|
);
|
|
84
|
-
config.$
|
|
85
|
-
config.$
|
|
84
|
+
config.$ngViewName = normalized.ngViewName;
|
|
85
|
+
config.$ngViewContextAnchor = normalized.ngViewContextAnchor;
|
|
86
86
|
views[name] = config;
|
|
87
87
|
});
|
|
88
88
|
return views;
|
|
@@ -101,10 +101,10 @@ export class Ng1ViewConfig {
|
|
|
101
101
|
|
|
102
102
|
/** @type {Number} */ this.$id = id++;
|
|
103
103
|
this.loaded = false;
|
|
104
|
-
this.getTemplate = (
|
|
104
|
+
this.getTemplate = (ngView, context) =>
|
|
105
105
|
this.component
|
|
106
106
|
? this.factory.makeComponentTemplate(
|
|
107
|
-
|
|
107
|
+
ngView,
|
|
108
108
|
context,
|
|
109
109
|
this.component,
|
|
110
110
|
this.viewDecl.bindings,
|
|
@@ -172,13 +172,13 @@ export class TemplateFactory {
|
|
|
172
172
|
* It analyses the component's bindings, then constructs a template that instantiates the component.
|
|
173
173
|
* The template wires input and output bindings to resolves or from the parent component.
|
|
174
174
|
*
|
|
175
|
-
* @param {angular.IAugmentedJQuery}
|
|
175
|
+
* @param {angular.IAugmentedJQuery} ngView {object} The parent ui-view (for binding outputs to callbacks)
|
|
176
176
|
* @param {angular.ResolveContext} context The ResolveContext (for binding outputs to callbacks returned from resolves)
|
|
177
177
|
* @param {string} component {string} Component's name in camel case.
|
|
178
178
|
* @param {any} [bindings] An object defining the component's bindings: {foo: '<'}
|
|
179
179
|
* @return {string} The template as a string: "<component-name input1='::$resolve.foo'></component-name>".
|
|
180
180
|
*/
|
|
181
|
-
makeComponentTemplate(
|
|
181
|
+
makeComponentTemplate(ngView, context, component, bindings) {
|
|
182
182
|
bindings = bindings || {};
|
|
183
183
|
// Bind once prefix
|
|
184
184
|
const prefix = "::"; //angular.version.minor >= 3 ? "::" : "";
|
|
@@ -194,8 +194,8 @@ export class TemplateFactory {
|
|
|
194
194
|
// If the ui-view has an attribute which matches a binding on the routed component
|
|
195
195
|
// then pass that attribute through to the routed component template.
|
|
196
196
|
// Prefer ui-view wired mappings to resolve data, unless the resolve was explicitly bound using `bindings:`
|
|
197
|
-
if (
|
|
198
|
-
return `${attrName}='${
|
|
197
|
+
if (ngView.attr(attrName) && !bindings[name])
|
|
198
|
+
return `${attrName}='${ngView.attr(attrName)}'`;
|
|
199
199
|
const resolveName = bindings[name] || name;
|
|
200
200
|
// Pre-evaluate the expression for "@" bindings by enclosing in {{ }}
|
|
201
201
|
// some-attr="{{ ::$resolve.someResolveName }}"
|
|
@@ -19,7 +19,7 @@ export class HookBuilder {
|
|
|
19
19
|
this.transition = transition;
|
|
20
20
|
}
|
|
21
21
|
buildHooksForPhase(phase) {
|
|
22
|
-
const $transitions = this.transition.
|
|
22
|
+
const $transitions = this.transition.transitionService;
|
|
23
23
|
return $transitions._pluginapi
|
|
24
24
|
._getEvents(phase)
|
|
25
25
|
.map((type) => this.buildHooks(type))
|
|
@@ -96,7 +96,7 @@ export class HookBuilder {
|
|
|
96
96
|
getMatchingHooks(hookType, treeChanges, transition) {
|
|
97
97
|
const isCreate = hookType.hookPhase === TransitionHookPhase.CREATE;
|
|
98
98
|
// Instance and Global hook registries
|
|
99
|
-
const $transitions = this.transition.
|
|
99
|
+
const $transitions = this.transition.transitionService;
|
|
100
100
|
const registries = isCreate
|
|
101
101
|
? [$transitions]
|
|
102
102
|
: [this.transition, $transitions];
|
|
@@ -7,6 +7,7 @@ import { trace } from "../common/trace";
|
|
|
7
7
|
import { services } from "../common/coreservices";
|
|
8
8
|
import { Rejection } from "./reject-factory";
|
|
9
9
|
import { TargetState } from "../state/target-state";
|
|
10
|
+
import { EventBus } from "../../core/pubsub";
|
|
10
11
|
const defaultOptions = {
|
|
11
12
|
current: () => {},
|
|
12
13
|
transition: null,
|
|
@@ -79,7 +80,7 @@ export class TransitionHook {
|
|
|
79
80
|
this.type = registeredHook.eventType;
|
|
80
81
|
}
|
|
81
82
|
logError(err) {
|
|
82
|
-
|
|
83
|
+
EventBus.publish("$stateService:defaultErrorHandler", err);
|
|
83
84
|
}
|
|
84
85
|
invokeHook() {
|
|
85
86
|
const hook = this.registeredHook;
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
registerAddCoreResolvables,
|
|
6
6
|
treeChangesCleanup,
|
|
7
7
|
} from "../hooks/core-resolvables";
|
|
8
|
-
import { registerRedirectToHook } from "../hooks/redirect-to";
|
|
9
8
|
import {
|
|
10
9
|
registerOnExitHook,
|
|
11
10
|
registerOnRetainHook,
|
|
@@ -16,17 +15,14 @@ import {
|
|
|
16
15
|
registerLazyResolveState,
|
|
17
16
|
registerResolveRemaining,
|
|
18
17
|
} from "../hooks/resolve";
|
|
19
|
-
import {
|
|
20
|
-
registerLoadEnteringViews,
|
|
21
|
-
registerActivateViews,
|
|
22
|
-
} from "../hooks/views";
|
|
18
|
+
import { registerLoadEnteringViews } from "../hooks/views";
|
|
23
19
|
import { registerUpdateGlobalState } from "../hooks/update-globals";
|
|
24
|
-
|
|
20
|
+
|
|
25
21
|
import { registerLazyLoadHook } from "../hooks/lazy-load";
|
|
26
22
|
import { TransitionEventType } from "./transition-event-type";
|
|
27
23
|
import { TransitionHook } from "./transition-hook";
|
|
28
24
|
import { isDefined } from "../../shared/utils";
|
|
29
|
-
import {
|
|
25
|
+
import { createProxyFunctions } from "../../shared/common";
|
|
30
26
|
import { val } from "../../shared/hof";
|
|
31
27
|
import { registerIgnoredTransitionHook } from "../hooks/ignored-transition";
|
|
32
28
|
import { registerInvalidTransitionHook } from "../hooks/invalid-transition";
|
|
@@ -61,9 +57,9 @@ export let defaultTransOpts = {
|
|
|
61
57
|
*/
|
|
62
58
|
export class TransitionService {
|
|
63
59
|
/**
|
|
64
|
-
* @param {import('../
|
|
60
|
+
* @param {import('../globals').UIRouterGlobals} globals
|
|
65
61
|
*/
|
|
66
|
-
constructor(
|
|
62
|
+
constructor(globals, viewService) {
|
|
67
63
|
this._transitionCount = 0;
|
|
68
64
|
/** The transition hook types, such as `onEnter`, `onStart`, etc */
|
|
69
65
|
this._eventTypes = [];
|
|
@@ -71,8 +67,8 @@ export class TransitionService {
|
|
|
71
67
|
this._registeredHooks = {};
|
|
72
68
|
/** The paths on a criteria object */
|
|
73
69
|
this._criteriaPaths = {};
|
|
74
|
-
this.
|
|
75
|
-
this.$view =
|
|
70
|
+
this.globals = globals;
|
|
71
|
+
this.$view = viewService;
|
|
76
72
|
this._deregisterHookFns = {};
|
|
77
73
|
this._pluginapi = createProxyFunctions(val(this), {}, val(this), [
|
|
78
74
|
"_definePathType",
|
|
@@ -84,7 +80,7 @@ export class TransitionService {
|
|
|
84
80
|
this._defineCorePaths();
|
|
85
81
|
this._defineCoreEvents();
|
|
86
82
|
this._registerCoreTransitionHooks();
|
|
87
|
-
|
|
83
|
+
globals.successfulTransitions.onEvict(treeChangesCleanup);
|
|
88
84
|
}
|
|
89
85
|
/**
|
|
90
86
|
* Registers a [[TransitionHookFn]], called *while a transition is being constructed*.
|
|
@@ -122,7 +118,7 @@ export class TransitionService {
|
|
|
122
118
|
* @returns a Transition
|
|
123
119
|
*/
|
|
124
120
|
create(fromPath, targetState) {
|
|
125
|
-
return new Transition(fromPath, targetState, this.
|
|
121
|
+
return new Transition(fromPath, targetState, this, this.globals);
|
|
126
122
|
}
|
|
127
123
|
|
|
128
124
|
_defineCoreEvents() {
|
|
@@ -242,8 +238,7 @@ export class TransitionService {
|
|
|
242
238
|
fns.addCoreResolves = registerAddCoreResolvables(this);
|
|
243
239
|
fns.ignored = registerIgnoredTransitionHook(this);
|
|
244
240
|
fns.invalid = registerInvalidTransitionHook(this);
|
|
245
|
-
|
|
246
|
-
fns.redirectTo = registerRedirectToHook(this);
|
|
241
|
+
|
|
247
242
|
// Wire up onExit/Retain/Enter state hooks
|
|
248
243
|
fns.onExit = registerOnExitHook(this);
|
|
249
244
|
fns.onRetain = registerOnRetainHook(this);
|
|
@@ -254,11 +249,9 @@ export class TransitionService {
|
|
|
254
249
|
fns.resolveAll = registerResolveRemaining(this);
|
|
255
250
|
// Wire up the View management hooks
|
|
256
251
|
fns.loadViews = registerLoadEnteringViews(this);
|
|
257
|
-
|
|
252
|
+
|
|
258
253
|
// Updates global state after a transition
|
|
259
254
|
fns.updateGlobals = registerUpdateGlobalState(this);
|
|
260
|
-
// After globals.current is updated at priority: 10000
|
|
261
|
-
fns.updateUrl = registerUpdateUrl(this);
|
|
262
255
|
// Lazy load state trees
|
|
263
256
|
fns.lazyLoad = registerLazyLoadHook(this);
|
|
264
257
|
}
|
|
@@ -35,20 +35,6 @@ const stateSelf = prop("self");
|
|
|
35
35
|
* It has information about all states being entered and exited as a result of the transition.
|
|
36
36
|
*/
|
|
37
37
|
export class Transition {
|
|
38
|
-
/**
|
|
39
|
-
* Creates the transition-level hook registration functions
|
|
40
|
-
* (which can then be used to register hooks)
|
|
41
|
-
*/
|
|
42
|
-
createTransitionHookRegFns() {
|
|
43
|
-
this.router.transitionService._pluginapi
|
|
44
|
-
._getEvents()
|
|
45
|
-
.filter((type) => type.hookPhase !== TransitionHookPhase.CREATE)
|
|
46
|
-
.forEach((type) => makeEvent(this, this.router.transitionService, type));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getHooks(hookName) {
|
|
50
|
-
return this._registeredHooks[hookName];
|
|
51
|
-
}
|
|
52
38
|
/**
|
|
53
39
|
* Creates a new Transition object.
|
|
54
40
|
*
|
|
@@ -59,10 +45,12 @@ export class Transition {
|
|
|
59
45
|
* @param fromPath The path of [[PathNode]]s from which the transition is leaving. The last node in the `fromPath`
|
|
60
46
|
* encapsulates the "from state".
|
|
61
47
|
* @param targetState The target state and parameters being transitioned to (also, the transition options)
|
|
62
|
-
* @param {import('../
|
|
48
|
+
* @param {import('../transition/transition-service').TransitionService} transitionService The [[TransitionService]] instance
|
|
63
49
|
* @internal
|
|
64
50
|
*/
|
|
65
|
-
constructor(fromPath, targetState,
|
|
51
|
+
constructor(fromPath, targetState, transitionService, globals) {
|
|
52
|
+
this.globals = globals;
|
|
53
|
+
this.transitionService = transitionService;
|
|
66
54
|
this._deferred = services.$q.defer();
|
|
67
55
|
/**
|
|
68
56
|
* This promise is resolved or rejected based on the outcome of the Transition.
|
|
@@ -76,8 +64,7 @@ export class Transition {
|
|
|
76
64
|
|
|
77
65
|
this._hookBuilder = new HookBuilder(this);
|
|
78
66
|
/** Checks if this transition is currently active/running. */
|
|
79
|
-
this.isActive = () => this.
|
|
80
|
-
this.router = router;
|
|
67
|
+
this.isActive = () => this.globals.transition === this;
|
|
81
68
|
this._targetState = targetState;
|
|
82
69
|
if (!targetState.valid()) {
|
|
83
70
|
throw new Error(targetState.error());
|
|
@@ -87,7 +74,7 @@ export class Transition {
|
|
|
87
74
|
{ current: val(this) },
|
|
88
75
|
targetState.options(),
|
|
89
76
|
);
|
|
90
|
-
this.$id =
|
|
77
|
+
this.$id = transitionService._transitionCount++;
|
|
91
78
|
const toPath = PathUtils.buildToPath(fromPath, targetState);
|
|
92
79
|
this._treeChanges = PathUtils.treeChanges(
|
|
93
80
|
fromPath,
|
|
@@ -99,12 +86,28 @@ export class Transition {
|
|
|
99
86
|
TransitionHookPhase.CREATE,
|
|
100
87
|
);
|
|
101
88
|
TransitionHook.invokeHooks(onCreateHooks, () => null);
|
|
102
|
-
this.applyViewConfigs(
|
|
89
|
+
this.applyViewConfigs();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates the transition-level hook registration functions
|
|
94
|
+
* (which can then be used to register hooks)
|
|
95
|
+
*/
|
|
96
|
+
createTransitionHookRegFns() {
|
|
97
|
+
this.transitionService._pluginapi
|
|
98
|
+
._getEvents()
|
|
99
|
+
.filter((type) => type.hookPhase !== TransitionHookPhase.CREATE)
|
|
100
|
+
.forEach((type) => makeEvent(this, this.transitionService, type));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getHooks(hookName) {
|
|
104
|
+
return this._registeredHooks[hookName];
|
|
103
105
|
}
|
|
104
|
-
|
|
106
|
+
|
|
107
|
+
applyViewConfigs() {
|
|
105
108
|
const enteringStates = this._treeChanges.entering.map((node) => node.state);
|
|
106
109
|
PathUtils.applyViewConfigs(
|
|
107
|
-
|
|
110
|
+
this.transitionService.$view,
|
|
108
111
|
this._treeChanges.to,
|
|
109
112
|
enteringStates,
|
|
110
113
|
);
|
|
@@ -475,7 +478,7 @@ export class Transition {
|
|
|
475
478
|
redirectOpts,
|
|
476
479
|
);
|
|
477
480
|
targetState = targetState.withOptions(newOptions, true);
|
|
478
|
-
const newTransition = this.
|
|
481
|
+
const newTransition = this.transitionService.create(
|
|
479
482
|
this._treeChanges.from,
|
|
480
483
|
targetState,
|
|
481
484
|
);
|
|
@@ -557,7 +560,7 @@ export class Transition {
|
|
|
557
560
|
}
|
|
558
561
|
|
|
559
562
|
_ignoredReason() {
|
|
560
|
-
const pending = this.
|
|
563
|
+
const pending = this.globals.transition;
|
|
561
564
|
const reloadState = this._options.reloadState;
|
|
562
565
|
const same = (pathA, pathB) => {
|
|
563
566
|
if (pathA.length !== pathB.length) return false;
|
|
@@ -619,7 +622,7 @@ export class Transition {
|
|
|
619
622
|
return TransitionHook.invokeHooks(allRunHooks, done);
|
|
620
623
|
};
|
|
621
624
|
const startTransition = () => {
|
|
622
|
-
const globals = this.
|
|
625
|
+
const globals = this.globals;
|
|
623
626
|
globals.lastStartedTransitionId = this.$id;
|
|
624
627
|
globals.transition = this;
|
|
625
628
|
globals.transitionHistory.enqueue(this);
|
|
@@ -14,12 +14,7 @@ import { isDefined, isString } from "../../shared/utils";
|
|
|
14
14
|
* This API is found at `router.urlService.config` (see: [[UIRouter.urlService]], [[URLService.config]])
|
|
15
15
|
*/
|
|
16
16
|
export class UrlConfig {
|
|
17
|
-
|
|
18
|
-
* @param {import('../router').UIRouter} router
|
|
19
|
-
*/
|
|
20
|
-
constructor(router) {
|
|
21
|
-
/** @type {import('../router').UIRouter} */
|
|
22
|
-
this.router = router;
|
|
17
|
+
constructor() {
|
|
23
18
|
/** @type {ParamTypes} */
|
|
24
19
|
this.paramTypes = new ParamTypes();
|
|
25
20
|
/** @type {boolean} */
|
|
@@ -30,49 +25,6 @@ export class UrlConfig {
|
|
|
30
25
|
this._isStrictMode = true;
|
|
31
26
|
/** @type {boolean} */
|
|
32
27
|
this._defaultSquashPolicy = false;
|
|
33
|
-
|
|
34
|
-
// Delegate these calls to the current LocationConfig implementation
|
|
35
|
-
/**
|
|
36
|
-
* Gets the base Href, e.g., `http://localhost/approot/`
|
|
37
|
-
*
|
|
38
|
-
* @return the application's base href
|
|
39
|
-
*/
|
|
40
|
-
this.baseHref = () => this.router.urlService.baseHref();
|
|
41
|
-
/**
|
|
42
|
-
* Gets or sets the hashPrefix
|
|
43
|
-
*
|
|
44
|
-
* This only applies when not running in [[html5Mode]] (pushstate mode)
|
|
45
|
-
*
|
|
46
|
-
* If the current url is `http://localhost/app#!/uirouter/path/#anchor`, it returns `!` which is the prefix for the "hashbang" portion.
|
|
47
|
-
*
|
|
48
|
-
* @return the hash prefix
|
|
49
|
-
*/
|
|
50
|
-
this.hashPrefix = (newprefix) =>
|
|
51
|
-
this.router.$locationProvider.hashPrefix(newprefix);
|
|
52
|
-
/**
|
|
53
|
-
* Gets the host, e.g., `localhost`
|
|
54
|
-
*
|
|
55
|
-
* @return {string} the protocol
|
|
56
|
-
*/
|
|
57
|
-
this.host = () => this.router.urlService.$location.host();
|
|
58
|
-
/**
|
|
59
|
-
* Returns true when running in pushstate mode
|
|
60
|
-
*
|
|
61
|
-
* @return {boolean} true when running in html5 mode (pushstate mode).
|
|
62
|
-
*/
|
|
63
|
-
this.html5Mode = () => this.router.urlService.html5Mode();
|
|
64
|
-
/**
|
|
65
|
-
* Gets the port, e.g., `80`
|
|
66
|
-
*
|
|
67
|
-
* @return {number} the port number
|
|
68
|
-
*/
|
|
69
|
-
this.port = () => this.router.urlService.$location.port();
|
|
70
|
-
/**
|
|
71
|
-
* Gets the protocol, e.g., `http`
|
|
72
|
-
*
|
|
73
|
-
* @return {string} the protocol
|
|
74
|
-
*/
|
|
75
|
-
this.protocol = () => this.router.urlService.$location.protocol();
|
|
76
28
|
}
|
|
77
29
|
/**
|
|
78
30
|
* Defines whether URL matching should be case sensitive (the default behavior), or not.
|