@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.
Files changed (82) hide show
  1. package/README.md +1 -2
  2. package/dist/angular-ts.esm.js +1 -1
  3. package/dist/angular-ts.umd.js +1 -1
  4. package/e2e/unit.spec.ts +2 -1
  5. package/index.html +8 -9
  6. package/package.json +1 -1
  7. package/src/core/pubsub.js +329 -0
  8. package/src/router/globals.js +0 -5
  9. package/src/router/hooks/core-resolvables.js +12 -11
  10. package/src/router/hooks/ignored-transition.js +1 -1
  11. package/src/router/hooks/lazy-load.js +40 -41
  12. package/src/router/hooks/redirect-to.js +32 -29
  13. package/src/router/hooks/update-globals.js +1 -1
  14. package/src/router/hooks/url.js +33 -24
  15. package/src/router/hooks/views.js +21 -20
  16. package/src/router/params/param-factory.js +17 -0
  17. package/src/router/params/param-types.js +0 -3
  18. package/src/router/router.js +78 -62
  19. package/src/router/services.js +2 -4
  20. package/src/router/state/state-queue-manager.js +5 -7
  21. package/src/router/state/state-registry.js +8 -10
  22. package/src/router/state/state-service.js +34 -33
  23. package/src/router/transition/hook-builder.js +2 -2
  24. package/src/router/transition/transition-hook.js +3 -9
  25. package/src/router/transition/transition-service.js +12 -30
  26. package/src/router/transition/transition.js +28 -25
  27. package/src/router/url/url-config.js +1 -49
  28. package/src/router/url/url-matcher-factory.js +10 -51
  29. package/src/router/url/url-router.js +27 -17
  30. package/src/router/url/url-rule.js +9 -13
  31. package/src/router/url/url-rules.js +3 -7
  32. package/src/router/url/url-service.js +134 -97
  33. package/src/router/view/view.js +3 -3
  34. package/src/shared/hof.js +1 -1
  35. package/test/angular.spec.js +1 -0
  36. package/test/aria/aria.spec.js +2 -1
  37. package/test/core/interval.spec.js +1 -1
  38. package/test/core/pubsub.spec.js +314 -0
  39. package/test/directive/bind.spec.js +2 -1
  40. package/test/directive/boolean.spec.js +4 -2
  41. package/test/directive/change.spec.js +1 -1
  42. package/test/directive/class.spec.js +1 -0
  43. package/test/directive/click.spec.js +2 -1
  44. package/test/directive/cloak.spec.js +1 -2
  45. package/test/directive/{constoller.spec.js → controller.spec.js} +1 -0
  46. package/test/directive/element-style.spec.js +1 -0
  47. package/test/directive/event.spec.js +1 -1
  48. package/test/directive/href.spec.js +2 -1
  49. package/test/directive/init.spec.js +1 -0
  50. package/test/directive/input.spec.js +200 -285
  51. package/test/directive/list.spec.js +2 -1
  52. package/test/directive/model.spec.js +1 -0
  53. package/test/directive/non-bindable.spec.js +2 -1
  54. package/test/directive/script.spec.js +1 -0
  55. package/test/directive/scrset.spec.js +2 -1
  56. package/test/directive/show-hide.spec.js +1 -0
  57. package/test/directive/src.spec.js +2 -1
  58. package/test/directive/style.spec.js +1 -0
  59. package/test/directive/switch.spec.js +2 -1
  60. package/test/directive/validators.spec.js +1 -1
  61. package/test/router/state-directives.spec.js +72 -72
  62. package/test/router/state.spec.js +5 -5
  63. package/test/router/template-factory.spec.js +2 -2
  64. package/test/router/view-directive.spec.js +65 -65
  65. package/test/router/view-hook.spec.js +13 -13
  66. package/test/router/view-scroll.spec.js +3 -3
  67. package/test/router/view.spec.js +2 -2
  68. package/types/router/core/common/coreservices.d.ts +2 -3
  69. package/types/router/core/globals.d.ts +1 -4
  70. package/types/router/core/interface.d.ts +2 -8
  71. package/types/router/core/params/paramTypes.d.ts +0 -1
  72. package/types/router/core/router.d.ts +2 -3
  73. package/types/router/core/state/stateQueueManager.d.ts +1 -3
  74. package/types/router/core/state/stateRegistry.d.ts +0 -2
  75. package/types/router/core/state/stateService.d.ts +1 -2
  76. package/types/router/core/transition/interface.d.ts +3 -3
  77. package/types/router/core/transition/transitionService.d.ts +1 -2
  78. package/types/router/core/url/urlConfig.d.ts +1 -2
  79. package/types/router/core/url/urlRules.d.ts +1 -2
  80. package/types/router/core/url/urlService.d.ts +1 -2
  81. package/types/router/locationServices.d.ts +0 -1
  82. package/src/router/location-services.js +0 -67
@@ -1,25 +1,34 @@
1
- /**
2
- * A [[TransitionHookFn]] which updates the URL after a successful transition
3
- *
4
- * Registered using `transitionService.onSuccess({}, updateUrl);`
5
- */
6
- const updateUrl = (transition) => {
7
- const options = transition.options();
8
- const $state = transition.router.stateService;
9
- const $urlRouter = transition.router.urlRouter;
10
- // Dont update the url in these situations:
11
- // The transition was triggered by a URL sync (options.source === 'url')
12
- // The user doesn't want the url to update (options.location === false)
13
- // The destination state, and all parents have no navigable url
14
- if (
15
- options.source !== "url" &&
16
- options.location &&
17
- $state.$current.navigable
18
- ) {
19
- const urlOptions = { replace: options.location === "replace" };
20
- $urlRouter.push($state.$current.navigable.url, $state.params, urlOptions);
21
- }
22
- $urlRouter.update(true);
23
- };
24
- export const registerUpdateUrl = (transitionService) =>
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
- * A [[TransitionHookFn]] which activates the new views when a transition is successful.
22
- *
23
- * Registered using `transitionService.onSuccess({}, activateViews);`
24
- *
25
- * After a transition is complete, this hook deactivates the old views from the previous state,
26
- * and activates the new views from the destination state.
27
- *
28
- * See [[ViewService]]
29
- */
30
- const activateViews = (transition) => {
31
- const enteringViews = transition.views("entering");
32
- const exitingViews = transition.views("exiting");
33
- if (!enteringViews.length && !exitingViews.length) return;
34
- const $view = transition.router.viewService;
35
- exitingViews.forEach((vc) => $view.deactivateViewConfig(vc));
36
- enteringViews.forEach((vc) => $view.activateViewConfig(vc));
37
- $view.sync();
38
- };
39
- export const registerActivateViews = (transitionService) =>
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
+ }
@@ -54,9 +54,6 @@ export class ParamTypes {
54
54
  new ParamType(Object.assign({ name }, definition));
55
55
  this.types = inherit(map(this.defaultTypes, makeType), {});
56
56
  }
57
- dispose() {
58
- this.types = {};
59
- }
60
57
  /**
61
58
  * Registers a parameter type
62
59
  *
@@ -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 {import('./location-services').Ng1LocationServices} locationService
32
+ * @param {angular.ILocationProvider} $locationProvider
30
33
  */
31
- constructor(locationService) {
32
- /**
33
- * @type {import('./location-services').Ng1LocationServices}
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(this);
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(this);
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(this);
57
- /** Provides services related to the URL */
58
- this.urlService = new UrlService(this);
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(this);
61
- /** Provides services related to states */
62
- this.stateService = new StateService(this);
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) {
@@ -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(ng1LocationService);
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
- ng1LocationService._runtimeServices($rootScope, $location, $browser);
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(router, states, builder, listeners) {
8
- this.router = router;
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.router.stateRegistry.deregister(existingFutureState);
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.router.urlService.rules;
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(router) {
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, router.urlMatcherFactory);
18
+ this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
19
19
  this.stateQueue = new StateQueueManager(
20
- router,
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.router.urlService.rules;
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.router.globals.params;
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.router.globals.current;
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.router.globals.$current;
52
+ return this.globals.$current;
59
53
  }
60
54
 
61
- constructor(router) {
62
- /** @private */
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
- dispose() {
89
- this.defaultErrorHandler(() => {});
90
- this.invalidCallbacks = [];
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.router.globals;
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.router.globals;
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 = router.globals.lastStartedTransitionId <= trans.$id;
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.router.transitionService.create(currentPath, ref);
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(schema, Param.values(schema, params), this.params);
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(schema, Param.values(schema, params), this.params);
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.router.transitionService.create(currentPath, target);
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.router.transitionService;
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.router.transitionService;
99
+ const $transitions = this.transition.transitionService;
100
100
  const registries = isCreate
101
101
  ? [$transitions]
102
102
  : [this.transition, $transitions];