@angular-wave/angular.ts 0.0.26 → 0.0.28
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 +8 -9
- package/package.json +1 -1
- package/src/core/pubsub.js +329 -0
- package/src/router/globals.js +0 -5
- 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/params/param-factory.js +17 -0
- package/src/router/params/param-types.js +0 -3
- package/src/router/router.js +78 -62
- package/src/router/services.js +2 -4
- package/src/router/state/state-queue-manager.js +5 -7
- package/src/router/state/state-registry.js +8 -10
- package/src/router/state/state-service.js +34 -33
- package/src/router/transition/hook-builder.js +2 -2
- package/src/router/transition/transition-hook.js +3 -9
- package/src/router/transition/transition-service.js +12 -30
- 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 +27 -17
- package/src/router/url/url-rule.js +9 -13
- package/src/router/url/url-rules.js +3 -7
- package/src/router/url/url-service.js +134 -97
- package/src/router/view/view.js +3 -3
- 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/interval.spec.js +1 -1
- package/test/core/pubsub.spec.js +314 -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/router/state-directives.spec.js +72 -72
- package/test/router/state.spec.js +5 -5
- package/test/router/template-factory.spec.js +2 -2
- package/test/router/view-directive.spec.js +65 -65
- package/test/router/view-hook.spec.js +13 -13
- package/test/router/view-scroll.spec.js +3 -3
- package/test/router/view.spec.js +2 -2
- 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/stateQueueManager.d.ts +1 -3
- package/types/router/core/state/stateRegistry.d.ts +0 -2
- package/types/router/core/state/stateService.d.ts +1 -2
- package/types/router/core/transition/interface.d.ts +3 -3
- 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/locationServices.d.ts +0 -1
- package/src/router/location-services.js +0 -67
package/src/router/hooks/url.js
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
options.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
export const registerUpdateUrl = (
|
|
2
|
+
transitionService,
|
|
3
|
+
stateService,
|
|
4
|
+
urlRouter,
|
|
5
|
+
) => {
|
|
6
|
+
/**
|
|
7
|
+
* A [[TransitionHookFn]] which updates the URL after a successful transition
|
|
8
|
+
*
|
|
9
|
+
* Registered using `transitionService.onSuccess({}, updateUrl);`
|
|
10
|
+
*/
|
|
11
|
+
const updateUrl = (transition) => {
|
|
12
|
+
const options = transition.options();
|
|
13
|
+
const $state = stateService;
|
|
14
|
+
const $urlRouter = urlRouter;
|
|
15
|
+
// Dont update the url in these situations:
|
|
16
|
+
// The transition was triggered by a URL sync (options.source === 'url')
|
|
17
|
+
// The user doesn't want the url to update (options.location === false)
|
|
18
|
+
// The destination state, and all parents have no navigable url
|
|
19
|
+
if (
|
|
20
|
+
options.source !== "url" &&
|
|
21
|
+
options.location &&
|
|
22
|
+
$state.$current.navigable
|
|
23
|
+
) {
|
|
24
|
+
const urlOptions = { replace: options.location === "replace" };
|
|
25
|
+
$urlRouter.push(
|
|
26
|
+
$state.$current.navigable.url,
|
|
27
|
+
$state.globals.params,
|
|
28
|
+
urlOptions,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
$urlRouter.update(true);
|
|
32
|
+
};
|
|
25
33
|
transitionService.onSuccess({}, updateUrl, { priority: 9999 });
|
|
34
|
+
};
|
|
@@ -17,24 +17,25 @@ const loadEnteringViews = (transition) => {
|
|
|
17
17
|
};
|
|
18
18
|
export const registerLoadEnteringViews = (transitionService) =>
|
|
19
19
|
transitionService.onFinish({}, loadEnteringViews);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
20
|
+
|
|
21
|
+
export const registerActivateViews = (transitionService, viewService) => {
|
|
22
|
+
/**
|
|
23
|
+
* A [[TransitionHookFn]] which activates the new views when a transition is successful.
|
|
24
|
+
*
|
|
25
|
+
* Registered using `transitionService.onSuccess({}, activateViews);`
|
|
26
|
+
*
|
|
27
|
+
* After a transition is complete, this hook deactivates the old views from the previous state,
|
|
28
|
+
* and activates the new views from the destination state.
|
|
29
|
+
*
|
|
30
|
+
* See [[ViewService]]
|
|
31
|
+
*/
|
|
32
|
+
const activateViews = (transition) => {
|
|
33
|
+
const enteringViews = transition.views("entering");
|
|
34
|
+
const exitingViews = transition.views("exiting");
|
|
35
|
+
if (!enteringViews.length && !exitingViews.length) return;
|
|
36
|
+
exitingViews.forEach((vc) => viewService.deactivateViewConfig(vc));
|
|
37
|
+
enteringViews.forEach((vc) => viewService.activateViewConfig(vc));
|
|
38
|
+
viewService.sync();
|
|
39
|
+
};
|
|
40
40
|
transitionService.onSuccess({}, activateViews);
|
|
41
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DefType, Param } from "../params/param";
|
|
2
|
+
|
|
3
|
+
export class ParamFactory {
|
|
4
|
+
constructor(urlServiceConfig) {
|
|
5
|
+
this.urlServiceConfig = urlServiceConfig;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
fromConfig(id, type, state) {
|
|
9
|
+
return new Param(id, type, DefType.CONFIG, this.urlServiceConfig, state);
|
|
10
|
+
}
|
|
11
|
+
fromPath(id, type, state) {
|
|
12
|
+
return new Param(id, type, DefType.PATH, this.urlServiceConfig, state);
|
|
13
|
+
}
|
|
14
|
+
fromSearch(id, type, state) {
|
|
15
|
+
return new Param(id, type, DefType.SEARCH, this.urlServiceConfig, state);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/router/router.js
CHANGED
|
@@ -5,10 +5,13 @@ import { ViewService } from "./view/view";
|
|
|
5
5
|
import { StateRegistry } from "./state/state-registry";
|
|
6
6
|
import { StateService } from "./state/state-service";
|
|
7
7
|
import { UIRouterGlobals } from "./globals";
|
|
8
|
-
import { removeFrom } from "../shared/common";
|
|
9
|
-
import { isFunction } from "../shared/utils";
|
|
10
8
|
import { UrlService } from "./url/url-service";
|
|
11
9
|
import { trace } from "./common/trace";
|
|
10
|
+
import { UrlRuleFactory } from "./url/url-rule";
|
|
11
|
+
import { registerLazyLoadHook } from "./hooks/lazy-load";
|
|
12
|
+
import { registerUpdateUrl } from "./hooks/url";
|
|
13
|
+
import { registerActivateViews } from "./hooks/views";
|
|
14
|
+
import { registerRedirectToHook } from "./hooks/redirect-to";
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* Router id tracker
|
|
@@ -26,86 +29,100 @@ export class UIRouter {
|
|
|
26
29
|
/**
|
|
27
30
|
* Creates a new `UIRouter` object
|
|
28
31
|
*
|
|
29
|
-
* @param {
|
|
32
|
+
* @param {angular.ILocationProvider} $locationProvider
|
|
30
33
|
*/
|
|
31
|
-
constructor(
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.locationService = locationService;
|
|
36
|
-
/** @type {number} */ this.$id = routerId++;
|
|
37
|
-
/** @type {boolean} */ this._disposed = false;
|
|
38
|
-
this._disposables = [];
|
|
34
|
+
constructor($locationProvider) {
|
|
35
|
+
/** @type {number} */
|
|
36
|
+
this.$id = routerId++;
|
|
37
|
+
|
|
39
38
|
/** Enable/disable tracing to the javascript console */
|
|
40
39
|
this.trace = trace;
|
|
40
|
+
this.$locationProvider = $locationProvider;
|
|
41
|
+
|
|
41
42
|
/** Provides services related to ui-view synchronization */
|
|
42
|
-
this.viewService = new ViewService(
|
|
43
|
+
this.viewService = new ViewService(routerId);
|
|
44
|
+
|
|
43
45
|
/** @type {UIRouterGlobals} An object that contains global router state, such as the current state and params */
|
|
44
46
|
this.globals = new UIRouterGlobals();
|
|
47
|
+
|
|
45
48
|
/** @type {TransitionService} A service that exposes global Transition Hooks */
|
|
46
|
-
this.transitionService = new TransitionService(
|
|
49
|
+
this.transitionService = new TransitionService(
|
|
50
|
+
this,
|
|
51
|
+
this.globals,
|
|
52
|
+
this.viewService,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** @type {StateService} Provides services related to states */
|
|
56
|
+
this.stateService = new StateService(
|
|
57
|
+
this, // access to StateRegistry and UrlRouter
|
|
58
|
+
this.globals,
|
|
59
|
+
this.transitionService,
|
|
60
|
+
);
|
|
61
|
+
/** Provides services related to the URL */
|
|
62
|
+
let urlRuleFactory = new UrlRuleFactory(
|
|
63
|
+
this.urlMatcherFactory,
|
|
64
|
+
this.stateService,
|
|
65
|
+
this.globals,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @type {angular.UrlService}
|
|
70
|
+
*/
|
|
71
|
+
this.urlService = new UrlService(
|
|
72
|
+
$locationProvider,
|
|
73
|
+
urlRuleFactory,
|
|
74
|
+
this.stateService,
|
|
75
|
+
);
|
|
76
|
+
|
|
47
77
|
/**
|
|
48
78
|
* Deprecated for public use. Use [[urlService]] instead.
|
|
49
79
|
* @deprecated Use [[urlService]] instead
|
|
50
80
|
*/
|
|
51
|
-
this.urlMatcherFactory = new UrlMatcherFactory(this);
|
|
81
|
+
this.urlMatcherFactory = new UrlMatcherFactory(this.urlService.config);
|
|
82
|
+
|
|
52
83
|
/**
|
|
53
84
|
* Deprecated for public use. Use [[urlService]] instead.
|
|
54
85
|
* @deprecated Use [[urlService]] instead
|
|
55
86
|
*/
|
|
56
|
-
this.urlRouter = new UrlRouter(
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
this.urlRouter = new UrlRouter(
|
|
88
|
+
this.urlService,
|
|
89
|
+
urlRuleFactory,
|
|
90
|
+
$locationProvider,
|
|
91
|
+
);
|
|
92
|
+
|
|
59
93
|
/** Provides a registry for states, and related registration services */
|
|
60
|
-
this.stateRegistry = new StateRegistry(
|
|
61
|
-
|
|
62
|
-
|
|
94
|
+
this.stateRegistry = new StateRegistry(
|
|
95
|
+
this.urlMatcherFactory,
|
|
96
|
+
this.urlService.rules,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Lazy load state trees
|
|
100
|
+
this.transitionService._deregisterHookFns.lazyLoad = registerLazyLoadHook(
|
|
101
|
+
this.transitionService,
|
|
102
|
+
this.stateService,
|
|
103
|
+
this.urlService,
|
|
104
|
+
this.stateRegistry,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// After globals.current is updated at priority: 10000
|
|
108
|
+
this.transitionService._deregisterHookFns.updateUrl = registerUpdateUrl(
|
|
109
|
+
this.transitionService,
|
|
110
|
+
this.stateService,
|
|
111
|
+
this.urlRouter,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Wire up redirectTo hook
|
|
115
|
+
this.transitionService._deregisterHookFns.redirectTo =
|
|
116
|
+
registerRedirectToHook(this.transitionService, this.stateService);
|
|
117
|
+
|
|
118
|
+
this.transitionService._deregisterHookFns.activateViews =
|
|
119
|
+
registerActivateViews(this.transitionService, this.viewService);
|
|
120
|
+
|
|
63
121
|
/** @internal plugin instances are registered here */
|
|
64
122
|
this._plugins = {};
|
|
65
123
|
this.viewService._pluginapi._rootViewContext(this.stateRegistry.root());
|
|
66
124
|
this.globals.$current = this.stateRegistry.root();
|
|
67
125
|
this.globals.current = this.globals.$current.self;
|
|
68
|
-
this.disposable(this.globals);
|
|
69
|
-
this.disposable(this.stateService);
|
|
70
|
-
this.disposable(this.stateRegistry);
|
|
71
|
-
this.disposable(this.transitionService);
|
|
72
|
-
this.disposable(this.urlService);
|
|
73
|
-
this.disposable(locationService);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Registers an object to be notified when the router is disposed
|
|
78
|
-
* @param {Disposable} disposable
|
|
79
|
-
* @returns {void}
|
|
80
|
-
*/
|
|
81
|
-
disposable(disposable) {
|
|
82
|
-
this._disposables.push(disposable);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Disposes this router instance
|
|
86
|
-
*
|
|
87
|
-
* When called, clears resources retained by the router by calling `dispose(this)` on all
|
|
88
|
-
* registered [[disposable]] objects.
|
|
89
|
-
*
|
|
90
|
-
* Or, if a `disposable` object is provided, calls `dispose(this)` on that object only.
|
|
91
|
-
*
|
|
92
|
-
* @internal
|
|
93
|
-
* @param disposable (optional) the disposable to dispose
|
|
94
|
-
*/
|
|
95
|
-
dispose(disposable) {
|
|
96
|
-
if (disposable && isFunction(disposable.dispose)) {
|
|
97
|
-
disposable.dispose(this);
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
this._disposed = true;
|
|
101
|
-
this._disposables.slice().forEach((d) => {
|
|
102
|
-
try {
|
|
103
|
-
typeof d.dispose === "function" && d.dispose(this);
|
|
104
|
-
removeFrom(this._disposables, d);
|
|
105
|
-
} catch (ignored) {
|
|
106
|
-
/* empty */
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
126
|
}
|
|
110
127
|
|
|
111
128
|
/**
|
|
@@ -167,7 +184,6 @@ export class UIRouter {
|
|
|
167
184
|
throw new Error(
|
|
168
185
|
"Required property `name` missing on plugin: " + pluginInstance,
|
|
169
186
|
);
|
|
170
|
-
this._disposables.push(pluginInstance);
|
|
171
187
|
return (this._plugins[pluginInstance.name] = pluginInstance);
|
|
172
188
|
}
|
|
173
189
|
getPlugin(pluginName) {
|
package/src/router/services.js
CHANGED
|
@@ -16,7 +16,6 @@ import { UIRouter } from "./router";
|
|
|
16
16
|
import { ng1ViewsBuilder, getNg1ViewConfigFactory } from "./state/views";
|
|
17
17
|
|
|
18
18
|
import { StateProvider } from "./state-provider";
|
|
19
|
-
import { Ng1LocationServices } from "./location-services";
|
|
20
19
|
import { ResolveContext } from "./resolve/resolve-context";
|
|
21
20
|
|
|
22
21
|
/** @type {angular.UIRouter}} */
|
|
@@ -24,9 +23,8 @@ export let router = null;
|
|
|
24
23
|
$routerProvider.$inject = ["$locationProvider"];
|
|
25
24
|
/** This angular 1 provider instantiates a Router and exposes its services via the angular injector */
|
|
26
25
|
export function $routerProvider($locationProvider) {
|
|
27
|
-
const ng1LocationService = new Ng1LocationServices($locationProvider);
|
|
28
26
|
// Create a new instance of the Router when the $routerProvider is initialized
|
|
29
|
-
router = this.router = new UIRouter(
|
|
27
|
+
router = this.router = new UIRouter($locationProvider);
|
|
30
28
|
router.stateProvider = new StateProvider(
|
|
31
29
|
router.stateRegistry,
|
|
32
30
|
router.stateService,
|
|
@@ -69,7 +67,7 @@ export function $routerProvider($locationProvider) {
|
|
|
69
67
|
router["$get"] = $get;
|
|
70
68
|
$get.$inject = ["$location", "$browser", "$rootScope"];
|
|
71
69
|
function $get($location, $browser, $rootScope) {
|
|
72
|
-
|
|
70
|
+
router.urlService._runtimeServices($rootScope, $location, $browser);
|
|
73
71
|
return router;
|
|
74
72
|
}
|
|
75
73
|
return router;
|
|
@@ -4,16 +4,14 @@ import { isString } from "../../shared/utils";
|
|
|
4
4
|
import { StateObject } from "./state-object";
|
|
5
5
|
|
|
6
6
|
export class StateQueueManager {
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(stateRegistry, urlServiceRules, states, builder, listeners) {
|
|
8
|
+
this.stateRegistry = stateRegistry;
|
|
9
|
+
this.urlServiceRules = urlServiceRules;
|
|
9
10
|
this.states = states;
|
|
10
11
|
this.builder = builder;
|
|
11
12
|
this.listeners = listeners;
|
|
12
13
|
this.queue = [];
|
|
13
14
|
}
|
|
14
|
-
dispose() {
|
|
15
|
-
this.queue = [];
|
|
16
|
-
}
|
|
17
15
|
register(stateDecl) {
|
|
18
16
|
const queue = this.queue;
|
|
19
17
|
const state = StateObject.create(stateDecl);
|
|
@@ -58,7 +56,7 @@ export class StateQueueManager {
|
|
|
58
56
|
const existingFutureState = getState(name + ".**");
|
|
59
57
|
if (existingFutureState) {
|
|
60
58
|
// Remove future state of the same name
|
|
61
|
-
this.
|
|
59
|
+
this.stateRegistry.deregister(existingFutureState);
|
|
62
60
|
}
|
|
63
61
|
states[name] = state;
|
|
64
62
|
this.attachRoute(state);
|
|
@@ -84,7 +82,7 @@ export class StateQueueManager {
|
|
|
84
82
|
}
|
|
85
83
|
attachRoute(state) {
|
|
86
84
|
if (state.abstract || !state.url) return;
|
|
87
|
-
const rulesApi = this.
|
|
85
|
+
const rulesApi = this.urlServiceRules;
|
|
88
86
|
rulesApi.rule(rulesApi.urlRuleFactory.create(state));
|
|
89
87
|
}
|
|
90
88
|
}
|
|
@@ -9,15 +9,16 @@ import { propEq } from "../../shared/hof";
|
|
|
9
9
|
* This API is found at `router.stateRegistry` ([[UIRouter.stateRegistry]])
|
|
10
10
|
*/
|
|
11
11
|
export class StateRegistry {
|
|
12
|
-
constructor(
|
|
13
|
-
this.router = router;
|
|
12
|
+
constructor(urlMatcherFactory, urlServiceRules) {
|
|
14
13
|
this.states = {};
|
|
14
|
+
this.urlServiceRules = urlServiceRules;
|
|
15
15
|
|
|
16
16
|
this.listeners = [];
|
|
17
17
|
this.matcher = new StateMatcher(this.states);
|
|
18
|
-
this.builder = new StateBuilder(this.matcher,
|
|
18
|
+
this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
|
|
19
19
|
this.stateQueue = new StateQueueManager(
|
|
20
|
-
|
|
20
|
+
this,
|
|
21
|
+
urlServiceRules,
|
|
21
22
|
this.states,
|
|
22
23
|
this.builder,
|
|
23
24
|
this.listeners,
|
|
@@ -39,11 +40,6 @@ export class StateRegistry {
|
|
|
39
40
|
_root.navigable = null;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
dispose() {
|
|
43
|
-
this.stateQueue.dispose();
|
|
44
|
-
this.listeners = [];
|
|
45
|
-
this.get().forEach((state) => this.get(state) && this.deregister(state));
|
|
46
|
-
}
|
|
47
43
|
/**
|
|
48
44
|
* Listen for a State Registry events
|
|
49
45
|
*
|
|
@@ -119,7 +115,7 @@ export class StateRegistry {
|
|
|
119
115
|
const children = getChildren([state]);
|
|
120
116
|
const deregistered = [state].concat(children).reverse();
|
|
121
117
|
deregistered.forEach((_state) => {
|
|
122
|
-
const rulesApi = this.
|
|
118
|
+
const rulesApi = this.urlServiceRules;
|
|
123
119
|
// Remove URL rule
|
|
124
120
|
rulesApi
|
|
125
121
|
.rules()
|
|
@@ -152,12 +148,14 @@ export class StateRegistry {
|
|
|
152
148
|
);
|
|
153
149
|
return deregisteredStates;
|
|
154
150
|
}
|
|
151
|
+
|
|
155
152
|
get(stateOrName, base) {
|
|
156
153
|
if (arguments.length === 0)
|
|
157
154
|
return Object.keys(this.states).map((name) => this.states[name].self);
|
|
158
155
|
const found = this.matcher.find(stateOrName, base);
|
|
159
156
|
return (found && found.self) || null;
|
|
160
157
|
}
|
|
158
|
+
|
|
161
159
|
/**
|
|
162
160
|
* Registers a [[BuilderFunction]] for a specific [[StateObject]] property (e.g., `parent`, `url`, or `path`).
|
|
163
161
|
* More than one BuilderFunction can be registered for a given property.
|
|
@@ -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,14 @@ 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
|
-
|
|
55
|
+
// Needs access to urlRouter, stateRegistry
|
|
56
|
+
constructor(router, globals, transitionService) {
|
|
63
57
|
this.router = router;
|
|
64
|
-
|
|
58
|
+
this.globals = globals;
|
|
59
|
+
this.transitionService = transitionService;
|
|
65
60
|
this.invalidCallbacks = [];
|
|
66
61
|
|
|
67
62
|
this._defaultErrorHandler = function $defaultErrorHandler($error$) {
|
|
@@ -83,12 +78,12 @@ export class StateService {
|
|
|
83
78
|
val(this),
|
|
84
79
|
boundFns,
|
|
85
80
|
);
|
|
86
|
-
}
|
|
87
81
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
EventBus.subscribe("$stateService:defaultErrorHandler", (err) =>
|
|
83
|
+
this.defaultErrorHandler()(err),
|
|
84
|
+
);
|
|
91
85
|
}
|
|
86
|
+
|
|
92
87
|
/**
|
|
93
88
|
* Handler for when [[transitionTo]] is called with an invalid state.
|
|
94
89
|
*
|
|
@@ -105,7 +100,7 @@ export class StateService {
|
|
|
105
100
|
this.router.stateRegistry,
|
|
106
101
|
fromPath,
|
|
107
102
|
);
|
|
108
|
-
const globals = this.
|
|
103
|
+
const globals = this.globals;
|
|
109
104
|
const latestThing = () => globals.transitionHistory.peekTail();
|
|
110
105
|
const latest = latestThing();
|
|
111
106
|
const callbackQueue = new Queue(this.invalidCallbacks.slice());
|
|
@@ -221,7 +216,7 @@ export class StateService {
|
|
|
221
216
|
* @returns A promise representing the state of the new transition. See [[StateService.go]]
|
|
222
217
|
*/
|
|
223
218
|
reload(reloadState) {
|
|
224
|
-
return this.transitionTo(this.current, this.params, {
|
|
219
|
+
return this.transitionTo(this.globals.current, this.globals.params, {
|
|
225
220
|
reload: isDefined(reloadState) ? reloadState : true,
|
|
226
221
|
inherit: false,
|
|
227
222
|
notify: false,
|
|
@@ -301,7 +296,7 @@ export class StateService {
|
|
|
301
296
|
}
|
|
302
297
|
|
|
303
298
|
getCurrentPath() {
|
|
304
|
-
const globals = this.
|
|
299
|
+
const globals = this.globals;
|
|
305
300
|
const latestSuccess = globals.successfulTransitions.peekTail();
|
|
306
301
|
const rootPath = () => [new PathNode(this.router.stateRegistry.root())];
|
|
307
302
|
return latestSuccess ? latestSuccess.treeChanges().to : rootPath();
|
|
@@ -330,10 +325,8 @@ export class StateService {
|
|
|
330
325
|
* @returns A promise representing the state of the new transition. See [[go]]
|
|
331
326
|
*/
|
|
332
327
|
transitionTo(to, toParams = {}, options = {}) {
|
|
333
|
-
const router = this.router;
|
|
334
|
-
const globals = router.globals;
|
|
335
328
|
options = defaults(options, defaultTransOpts);
|
|
336
|
-
const getCurrent = () => globals.transition;
|
|
329
|
+
const getCurrent = () => this.globals.transition;
|
|
337
330
|
options = Object.assign(options, { current: getCurrent });
|
|
338
331
|
const ref = this.target(to, toParams, options);
|
|
339
332
|
const currentPath = this.getCurrentPath();
|
|
@@ -355,11 +348,11 @@ export class StateService {
|
|
|
355
348
|
*/
|
|
356
349
|
const rejectedTransitionHandler = (trans) => (error) => {
|
|
357
350
|
if (error instanceof Rejection) {
|
|
358
|
-
const isLatest =
|
|
351
|
+
const isLatest = this.globals.lastStartedTransitionId <= trans.$id;
|
|
359
352
|
if (error.type === RejectType.IGNORED) {
|
|
360
|
-
isLatest && router.urlRouter.update();
|
|
353
|
+
isLatest && this.router.urlRouter.update();
|
|
361
354
|
// Consider ignored `Transition.run()` as a successful `transitionTo`
|
|
362
|
-
return services.$q.when(globals.current);
|
|
355
|
+
return services.$q.when(this.globals.current);
|
|
363
356
|
}
|
|
364
357
|
const detail = error.detail;
|
|
365
358
|
if (
|
|
@@ -373,7 +366,7 @@ export class StateService {
|
|
|
373
366
|
return redirect.run().catch(rejectedTransitionHandler(redirect));
|
|
374
367
|
}
|
|
375
368
|
if (error.type === RejectType.ABORTED) {
|
|
376
|
-
isLatest && router.urlRouter.update();
|
|
369
|
+
isLatest && this.router.urlRouter.update();
|
|
377
370
|
return services.$q.reject(error);
|
|
378
371
|
}
|
|
379
372
|
}
|
|
@@ -381,7 +374,7 @@ export class StateService {
|
|
|
381
374
|
errorHandler(error);
|
|
382
375
|
return services.$q.reject(error);
|
|
383
376
|
};
|
|
384
|
-
const transition = this.
|
|
377
|
+
const transition = this.transitionService.create(currentPath, ref);
|
|
385
378
|
const transitionToPromise = transition
|
|
386
379
|
.run()
|
|
387
380
|
.catch(rejectedTransitionHandler(transition));
|
|
@@ -430,7 +423,11 @@ export class StateService {
|
|
|
430
423
|
if (this.$current !== state) return false;
|
|
431
424
|
if (!params) return true;
|
|
432
425
|
const schema = state.parameters({ inherit: true, matchingKeys: params });
|
|
433
|
-
return Param.equals(
|
|
426
|
+
return Param.equals(
|
|
427
|
+
schema,
|
|
428
|
+
Param.values(schema, params),
|
|
429
|
+
this.globals.params,
|
|
430
|
+
);
|
|
434
431
|
}
|
|
435
432
|
/**
|
|
436
433
|
* Checks if the current state *includes* the provided state
|
|
@@ -486,7 +483,11 @@ export class StateService {
|
|
|
486
483
|
if (!isDefined(include[state.name])) return false;
|
|
487
484
|
if (!params) return true;
|
|
488
485
|
const schema = state.parameters({ inherit: true, matchingKeys: params });
|
|
489
|
-
return Param.equals(
|
|
486
|
+
return Param.equals(
|
|
487
|
+
schema,
|
|
488
|
+
Param.values(schema, params),
|
|
489
|
+
this.globals.params,
|
|
490
|
+
);
|
|
490
491
|
}
|
|
491
492
|
/**
|
|
492
493
|
* Generates a URL for a state and parameters
|
|
@@ -519,7 +520,7 @@ export class StateService {
|
|
|
519
520
|
);
|
|
520
521
|
if (!isDefined(state)) return null;
|
|
521
522
|
if (options.inherit)
|
|
522
|
-
params = this.params.$inherit(params, this.$current, state);
|
|
523
|
+
params = this.globals.params.$inherit(params, this.$current, state);
|
|
523
524
|
const nav = state && options.lossy ? state.navigable : state;
|
|
524
525
|
if (!nav || nav.url === undefined || nav.url === null) {
|
|
525
526
|
return null;
|
|
@@ -582,7 +583,7 @@ export class StateService {
|
|
|
582
583
|
currentPath,
|
|
583
584
|
);
|
|
584
585
|
transition =
|
|
585
|
-
transition || this.
|
|
586
|
+
transition || this.transitionService.create(currentPath, target);
|
|
586
587
|
return lazyLoadState(transition, state);
|
|
587
588
|
}
|
|
588
589
|
}
|
|
@@ -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];
|