Skip to content

Commit 611183a

Browse files
refactor(urlService): Move public API implementations from UrlRouter to UrlService
Migrate towards accessing services from router instance, i.e., router.urlService.rules.method()
1 parent 857932d commit 611183a

13 files changed

+417
-429
lines changed

src/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class UIRouter {
134134
this.disposable(this.stateService);
135135
this.disposable(this.stateRegistry);
136136
this.disposable(this.transitionService);
137-
this.disposable(this.urlRouter);
137+
this.disposable(this.urlService);
138138
this.disposable(locationService);
139139
this.disposable(locationConfig);
140140
}

src/state/stateQueueManager.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
/** @module state */ /** for typedoc */
2-
import { inArray } from '../common/common';
3-
import { isString } from '../common/predicates';
4-
import { StateDeclaration, _StateDeclaration } from './interface';
1+
/** @module state */
2+
/** for typedoc */
3+
import { inArray, isString, prop } from '../common';
4+
import { _StateDeclaration } from './interface';
55
import { StateObject } from './stateObject';
66
import { StateBuilder } from './stateBuilder';
7-
import { StateRegistryListener, StateRegistry } from './stateRegistry';
7+
import { StateRegistryListener } from './stateRegistry';
88
import { Disposable } from '../interface';
9-
import { UrlRouter } from '../url/urlRouter';
10-
import { prop } from '../common/hof';
11-
import { StateMatcher } from './stateMatcher';
9+
import { UIRouter } from '../router';
1210

1311
/** @internalapi */
1412
export class StateQueueManager implements Disposable {
15-
queue: StateObject[];
16-
matcher: StateMatcher;
13+
queue: StateObject[] = [];
1714

1815
constructor(
19-
private $registry: StateRegistry,
20-
private $urlRouter: UrlRouter,
16+
private router: UIRouter,
2117
public states: { [key: string]: StateObject },
2218
public builder: StateBuilder,
2319
public listeners: StateRegistryListener[]
24-
) {
25-
this.queue = [];
26-
this.matcher = $registry.matcher;
27-
}
20+
) {}
2821

2922
/** @internalapi */
3023
dispose() {
@@ -73,7 +66,7 @@ export class StateQueueManager implements Disposable {
7366
const existingFutureState = getState(name + '.**');
7467
if (existingFutureState) {
7568
// Remove future state of the same name
76-
this.$registry.deregister(existingFutureState);
69+
this.router.stateRegistry.deregister(existingFutureState);
7770
}
7871

7972
states[name] = state;
@@ -104,7 +97,7 @@ export class StateQueueManager implements Disposable {
10497

10598
attachRoute(state: StateObject) {
10699
if (state.abstract || !state.url) return;
107-
108-
this.$urlRouter.rule(this.$urlRouter.urlRuleFactory.create(state));
100+
const rulesApi = this.router.urlService.rules;
101+
rulesApi.rule(rulesApi.urlRuleFactory.create(state));
109102
}
110103
}

src/state/stateRegistry.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export class StateRegistry {
3535
listeners: StateRegistryListener[] = [];
3636

3737
/** @internalapi */
38-
constructor(private _router: UIRouter) {
38+
constructor(private router: UIRouter) {
3939
this.matcher = new StateMatcher(this.states);
40-
this.builder = new StateBuilder(this.matcher, _router.urlMatcherFactory);
41-
this.stateQueue = new StateQueueManager(this, _router.urlRouter, this.states, this.builder, this.listeners);
40+
this.builder = new StateBuilder(this.matcher, router.urlMatcherFactory);
41+
this.stateQueue = new StateQueueManager(router, this.states, this.builder, this.listeners);
4242
this._registerRoot();
4343
}
4444

@@ -143,12 +143,14 @@ export class StateRegistry {
143143
const deregistered: StateObject[] = [state].concat(children).reverse();
144144

145145
deregistered.forEach(_state => {
146-
const $ur = this._router.urlRouter;
146+
const rulesApi = this.router.urlService.rules;
147+
147148
// Remove URL rule
148-
$ur
149+
rulesApi
149150
.rules()
150151
.filter(propEq('state', _state))
151-
.forEach($ur.removeRule.bind($ur));
152+
.forEach(rule => rulesApi.removeRule(rule));
153+
152154
// Remove state from registry
153155
delete this.states[_state.name];
154156
});

src/state/stateService.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,8 @@ export class StateService {
524524
if (!nav || nav.url === undefined || nav.url === null) {
525525
return null;
526526
}
527-
return this.router.urlRouter.href(nav.url, params, {
528-
absolute: options.absolute,
529-
});
527+
528+
return this.router.urlRouter.href(nav.url, params, { absolute: options.absolute });
530529
}
531530

532531
/** @hidden */

src/url/urlMatcherFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class UrlMatcherFactory implements Disposable, UrlMatcherConfig {
4545
/** @internalapi Creates a new [[Param]] for a given location (DefType) */
4646
paramFactory = new ParamFactory(this);
4747

48+
// TODO: move implementations to UrlConfig (urlService.config)
4849
constructor() {
4950
extend(this, { UrlMatcher, Param });
5051
}

0 commit comments

Comments
 (0)