@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
@@ -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
- this.transition.router.stateService.defaultErrorHandler()(err);
83
+ EventBus.publish("$stateService:defaultErrorHandler", err);
83
84
  }
84
85
  invokeHook() {
85
86
  const hook = this.registeredHook;
@@ -142,16 +143,9 @@ export class TransitionHook {
142
143
  }
143
144
  /**
144
145
  * Return a Rejection promise if the transition is no longer current due
145
- * to a stopped router (disposed), or a new transition has started and superseded this one.
146
+ * a new transition has started and superseded this one.
146
147
  */
147
148
  getNotCurrentRejection() {
148
- const router = this.transition.router;
149
- // The router is stopped
150
- if (router._disposed) {
151
- return Rejection.aborted(
152
- `UIRouter instance #${router.$id} has been stopped (disposed)`,
153
- ).toPromise();
154
- }
155
149
  if (this.transition._aborted) {
156
150
  return Rejection.aborted().toPromise();
157
151
  }
@@ -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
- import { registerUpdateUrl } from "../hooks/url";
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 { removeFrom, createProxyFunctions } from "../../shared/common";
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('../router').UIRouter} _router
60
+ * @param {import('../router').UIRouter} router
65
61
  */
66
- constructor(_router) {
62
+ constructor(router, 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,9 @@ export class TransitionService {
71
67
  this._registeredHooks = {};
72
68
  /** The paths on a criteria object */
73
69
  this._criteriaPaths = {};
74
- this._router = _router;
75
- this.$view = _router.viewService;
70
+ this.router = router;
71
+ this.globals = globals;
72
+ this.$view = viewService;
76
73
  this._deregisterHookFns = {};
77
74
  this._pluginapi = createProxyFunctions(val(this), {}, val(this), [
78
75
  "_definePathType",
@@ -84,7 +81,7 @@ export class TransitionService {
84
81
  this._defineCorePaths();
85
82
  this._defineCoreEvents();
86
83
  this._registerCoreTransitionHooks();
87
- _router.globals.successfulTransitions.onEvict(treeChangesCleanup);
84
+ globals.successfulTransitions.onEvict(treeChangesCleanup);
88
85
  }
89
86
  /**
90
87
  * Registers a [[TransitionHookFn]], called *while a transition is being constructed*.
@@ -110,18 +107,6 @@ export class TransitionService {
110
107
  * @returns a function which deregisters the hook.
111
108
  */
112
109
 
113
- /**
114
- * dispose
115
- * @internal
116
- */
117
- dispose() {
118
- Object.values(this._registeredHooks).forEach((hooksArray) =>
119
- hooksArray.forEach((hook) => {
120
- hook._deregistered = true;
121
- removeFrom(hooksArray, hook);
122
- }),
123
- );
124
- }
125
110
  /**
126
111
  * Creates a new [[Transition]] object
127
112
  *
@@ -134,7 +119,7 @@ export class TransitionService {
134
119
  * @returns a Transition
135
120
  */
136
121
  create(fromPath, targetState) {
137
- return new Transition(fromPath, targetState, this._router);
122
+ return new Transition(fromPath, targetState, this, this.globals);
138
123
  }
139
124
 
140
125
  _defineCoreEvents() {
@@ -254,8 +239,7 @@ export class TransitionService {
254
239
  fns.addCoreResolves = registerAddCoreResolvables(this);
255
240
  fns.ignored = registerIgnoredTransitionHook(this);
256
241
  fns.invalid = registerInvalidTransitionHook(this);
257
- // Wire up redirectTo hook
258
- fns.redirectTo = registerRedirectToHook(this);
242
+
259
243
  // Wire up onExit/Retain/Enter state hooks
260
244
  fns.onExit = registerOnExitHook(this);
261
245
  fns.onRetain = registerOnRetainHook(this);
@@ -266,11 +250,9 @@ export class TransitionService {
266
250
  fns.resolveAll = registerResolveRemaining(this);
267
251
  // Wire up the View management hooks
268
252
  fns.loadViews = registerLoadEnteringViews(this);
269
- fns.activateViews = registerActivateViews(this);
253
+
270
254
  // Updates global state after a transition
271
255
  fns.updateGlobals = registerUpdateGlobalState(this);
272
- // After globals.current is updated at priority: 10000
273
- fns.updateUrl = registerUpdateUrl(this);
274
256
  // Lazy load state trees
275
257
  fns.lazyLoad = registerLazyLoadHook(this);
276
258
  }
@@ -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('../router').UIRouter} router The [[UIRouter]] instance
48
+ * @param {import('../transition/transition-service').TransitionService} transitionService The [[TransitionService]] instance
63
49
  * @internal
64
50
  */
65
- constructor(fromPath, targetState, router) {
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.router.globals.transition === 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 = router.transitionService._transitionCount++;
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(router);
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
- applyViewConfigs(router) {
106
+
107
+ applyViewConfigs() {
105
108
  const enteringStates = this._treeChanges.entering.map((node) => node.state);
106
109
  PathUtils.applyViewConfigs(
107
- router.transitionService.$view,
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.router.transitionService.create(
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.router.globals.transition;
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.router.globals;
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
- this.dispose = () => this.paramTypes.dispose();
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.locationService.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.locationService.$locationProvider.hashPrefix(newprefix);
52
- /**
53
- * Gets the host, e.g., `localhost`
54
- *
55
- * @return {string} the protocol
56
- */
57
- this.host = () => this.router.locationService.$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.locationService.html5Mode();
64
- /**
65
- * Gets the port, e.g., `80`
66
- *
67
- * @return {number} the port number
68
- */
69
- this.port = () => this.router.locationService.$location.port();
70
- /**
71
- * Gets the protocol, e.g., `http`
72
- *
73
- * @return {string} the protocol
74
- */
75
- this.protocol = () => this.router.locationService.$location.protocol();
76
28
  }
77
29
  /**
78
30
  * Defines whether URL matching should be case sensitive (the default behavior), or not.
@@ -1,40 +1,7 @@
1
1
  import { forEach, isDefined, isFunction, isObject } from "../../shared/utils";
2
2
  import { UrlMatcher } from "./url-matcher";
3
- import { DefType, Param } from "../params/param";
3
+ import { ParamFactory } from "../params/param-factory";
4
4
 
5
- export class ParamFactory {
6
- constructor(router) {
7
- this.router = router;
8
- }
9
-
10
- fromConfig(id, type, state) {
11
- return new Param(
12
- id,
13
- type,
14
- DefType.CONFIG,
15
- this.router.urlService.config,
16
- state,
17
- );
18
- }
19
- fromPath(id, type, state) {
20
- return new Param(
21
- id,
22
- type,
23
- DefType.PATH,
24
- this.router.urlService.config,
25
- state,
26
- );
27
- }
28
- fromSearch(id, type, state) {
29
- return new Param(
30
- id,
31
- type,
32
- DefType.SEARCH,
33
- this.router.urlService.config,
34
- state,
35
- );
36
- }
37
- }
38
5
  /**
39
6
  * Factory for [[UrlMatcher]] instances.
40
7
  *
@@ -43,28 +10,20 @@ export class ParamFactory {
43
10
  */
44
11
  export class UrlMatcherFactory {
45
12
  // TODO: move implementations to UrlConfig (urlService.config)
46
- constructor(router) {
47
- this.router = router;
13
+ constructor(urlServiceConfig) {
14
+ this.urlServiceConfig = urlServiceConfig;
48
15
  /** Creates a new [[Param]] for a given location (DefType) */
49
- this.paramFactory = new ParamFactory(this.router);
50
- // TODO: Check if removal of this will break anything, then remove these
51
- this.UrlMatcher = UrlMatcher;
52
- this.Param = Param;
16
+ this.paramFactory = new ParamFactory(urlServiceConfig);
53
17
  /** @deprecated use [[UrlConfig.caseInsensitive]] */
54
- this.caseInsensitive = (value) =>
55
- this.router.urlService.config.caseInsensitive(value);
18
+ this.caseInsensitive = (value) => urlServiceConfig.caseInsensitive(value);
56
19
  /** @deprecated use [[UrlConfig.defaultSquashPolicy]] */
57
20
  this.defaultSquashPolicy = (value) =>
58
- this.router.urlService.config.defaultSquashPolicy(value);
21
+ urlServiceConfig.defaultSquashPolicy(value);
59
22
  /** @deprecated use [[UrlConfig.strictMode]] */
60
- this.strictMode = (value) =>
61
- this.router.urlService.config.strictMode(value);
23
+ this.strictMode = (value) => urlServiceConfig.strictMode(value);
62
24
  /** @deprecated use [[UrlConfig.type]] */
63
25
  this.type = (name, definition, definitionFn) => {
64
- return (
65
- this.router.urlService.config.type(name, definition, definitionFn) ||
66
- this
67
- );
26
+ return urlServiceConfig.type(name, definition, definitionFn) || this;
68
27
  };
69
28
  }
70
29
  /**
@@ -75,7 +34,7 @@ export class UrlMatcherFactory {
75
34
  * @returns The UrlMatcher.
76
35
  */
77
36
  compile(pattern, config) {
78
- const urlConfig = this.router.urlService.config;
37
+ const urlConfig = this.urlServiceConfig;
79
38
  // backward-compatible support for config.params -> config.state.params
80
39
  const params = config && !config.state && config.params;
81
40
  config = params ? Object.assign({ state: { params } }, config) : config;
@@ -110,7 +69,7 @@ export class UrlMatcherFactory {
110
69
  }
111
70
 
112
71
  $get() {
113
- const urlConfig = this.router.urlService.config;
72
+ const urlConfig = this.urlServiceConfig;
114
73
  urlConfig.paramTypes.enqueue = false;
115
74
  urlConfig.paramTypes._flushTypeQueue();
116
75
  return this;
@@ -1,5 +1,5 @@
1
1
  import { stripLastPathElement } from "../../shared/strings";
2
- import { UrlRuleFactory } from "./url-rule";
2
+
3
3
  function appendBasePath(url, isHtml5, absolute, baseHref) {
4
4
  if (baseHref === "/") return url;
5
5
  if (isHtml5) return stripLastPathElement(baseHref) + url;
@@ -16,16 +16,16 @@ function appendBasePath(url, isHtml5, absolute, baseHref) {
16
16
  */
17
17
  export class UrlRouter {
18
18
  /**
19
- *
20
- * @param {import('../router').UIRouter} router
19
+ * @param {angular.UrlService} urlService
21
20
  */
22
- constructor(router) {
23
- this.router = router;
24
- this.urlRuleFactory = new UrlRuleFactory(router);
21
+ constructor(urlService, urlRuleFactory, $locationProvider) {
22
+ this.urlService = urlService;
23
+ this.urlRuleFactory = urlRuleFactory;
24
+ this.$locationProvider = $locationProvider;
25
25
  }
26
- /** Internal API. */
26
+
27
27
  update(read) {
28
- const $url = this.router.locationService;
28
+ const $url = this.urlService;
29
29
  if (read) {
30
30
  this.location = $url.url();
31
31
  return;
@@ -34,8 +34,6 @@ export class UrlRouter {
34
34
  $url.url(this.location, true);
35
35
  }
36
36
  /**
37
- * Internal API.
38
- *
39
37
  * Pushes a new location to the browser history.
40
38
  *
41
39
  * @internal
@@ -45,7 +43,7 @@ export class UrlRouter {
45
43
  */
46
44
  push(urlMatcher, params, options) {
47
45
  const replace = options && !!options.replace;
48
- this.router.urlService.url(urlMatcher.format(params || {}), replace);
46
+ this.urlService.url(urlMatcher.format(params || {}), replace);
49
47
  }
50
48
  /**
51
49
  * Builds and returns a URL with interpolated parameters
@@ -70,18 +68,30 @@ export class UrlRouter {
70
68
  let url = urlMatcher.format(params);
71
69
  if (url == null) return null;
72
70
  options = options || { absolute: false };
73
- const cfg = this.router.urlService.config;
74
- const isHtml5 = cfg.html5Mode();
71
+ const cfg = this.urlService.config;
72
+ const isHtml5 = this.urlService.html5Mode();
75
73
  if (!isHtml5 && url !== null) {
76
- url = "#" + cfg.hashPrefix() + url;
74
+ url = "#" + this.$locationProvider.hashPrefix() + url;
77
75
  }
78
- url = appendBasePath(url, isHtml5, options.absolute, cfg.baseHref());
76
+ url = appendBasePath(
77
+ url,
78
+ isHtml5,
79
+ options.absolute,
80
+ this.urlService.baseHref(),
81
+ );
79
82
  if (!options.absolute || !url) {
80
83
  return url;
81
84
  }
82
85
  const slash = !isHtml5 && url ? "/" : "";
83
- const cfgPort = cfg.port();
86
+ const cfgPort = this.urlService.$location.port();
84
87
  const port = cfgPort === 80 || cfgPort === 443 ? "" : ":" + cfgPort;
85
- return [cfg.protocol(), "://", cfg.host(), port, slash, url].join("");
88
+ return [
89
+ cfg.protocol(),
90
+ "://",
91
+ this.urlService.$location.host(),
92
+ port,
93
+ slash,
94
+ url,
95
+ ].join("");
86
96
  }
87
97
  }
@@ -13,12 +13,10 @@ import { StateObject } from "../state/state-object";
13
13
  * - [[StateObject]]
14
14
  */
15
15
  export class UrlRuleFactory {
16
- constructor(router) {
17
- this.router = router;
18
- }
19
-
20
- compile(str) {
21
- return this.router.urlMatcherFactory.compile(str);
16
+ constructor(urlMatcherFactory, stateService, routerGlobals) {
17
+ this.urlMatcherFactory = urlMatcherFactory;
18
+ this.stateService = stateService;
19
+ this.routerGlobals = routerGlobals;
22
20
  }
23
21
 
24
22
  /**
@@ -30,11 +28,11 @@ export class UrlRuleFactory {
30
28
  create(what, handler) {
31
29
  const { isState, isStateDeclaration } = StateObject;
32
30
  const makeRule = pattern([
33
- [isString, (_what) => makeRule(this.compile(_what))],
31
+ [isString, (_what) => makeRule(this.urlMatcherFactory.compile(_what))],
34
32
  [is(UrlMatcher), (_what) => this.fromUrlMatcher(_what, handler)],
35
33
  [
36
34
  or(isState, isStateDeclaration),
37
- (_what) => this.fromState(_what, this.router),
35
+ (_what) => this.fromState(_what, this.stateService, this.routerGlobals),
38
36
  ],
39
37
  [is(RegExp), (_what) => this.fromRegExp(_what, handler)],
40
38
  [isFunction, (_what) => new BaseUrlRule(_what, handler)],
@@ -81,8 +79,7 @@ export class UrlRuleFactory {
81
79
  */
82
80
  fromUrlMatcher(urlMatcher, handler) {
83
81
  let _handler = handler;
84
- if (isString(handler))
85
- handler = this.router.urlMatcherFactory.compile(handler);
82
+ if (isString(handler)) handler = this.urlMatcherFactory.compile(handler);
86
83
  if (is(UrlMatcher)(handler)) _handler = (match) => handler.format(match);
87
84
  function matchUrlParamters(url) {
88
85
  const params = urlMatcher.exec(url.path, url.search, url.hash);
@@ -115,7 +112,7 @@ export class UrlRuleFactory {
115
112
  * // Starts a transition to 'foo' with params: { fooId: '123', barId: '456' }
116
113
  * ```
117
114
  */
118
- fromState(stateOrDecl, router) {
115
+ fromState(stateOrDecl, stateService, globals) {
119
116
  const state = StateObject.isStateDeclaration(stateOrDecl)
120
117
  ? stateOrDecl.$$state()
121
118
  : stateOrDecl;
@@ -127,8 +124,7 @@ export class UrlRuleFactory {
127
124
  * and the new URL are already identical
128
125
  */
129
126
  const handler = (match) => {
130
- const $state = router.stateService;
131
- const globals = router.globals;
127
+ const $state = stateService;
132
128
  if (
133
129
  $state.href(state, match) !==
134
130
  $state.href(globals.current, globals.params)
@@ -62,20 +62,16 @@ function getHandlerFn(handler) {
62
62
  *
63
63
  * The most commonly used methods are [[otherwise]] and [[when]].
64
64
  *
65
- * This API is found at `router.urlService.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])
65
+ * This API is found at `$urlService.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])
66
66
  */
67
67
  export class UrlRules {
68
- constructor(router) {
68
+ constructor(urlRuleFactory) {
69
69
  this._sortFn = defaultRuleSortFn;
70
70
  this._rules = [];
71
71
  this._id = 0;
72
- this.urlRuleFactory = new UrlRuleFactory(router);
72
+ this.urlRuleFactory = urlRuleFactory;
73
73
  }
74
74
 
75
- dispose() {
76
- this._rules = [];
77
- delete this._otherwiseFn;
78
- }
79
75
  /**
80
76
  * Defines the initial state, path, or behavior to use when the app starts.
81
77
  *