Skip to content

Commit 60defb7

Browse files
refactor(state): remove dependency from stateRegistry to StateService
1 parent 5dcd4bc commit 60defb7

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class UIRouter {
3535

3636
viewService = new ViewService(this.templateFactory);
3737

38-
stateRegistry: StateRegistry = new StateRegistry(this.urlMatcherFactory, this.urlRouterProvider, () => this.stateService.$current);
38+
stateRegistry: StateRegistry = new StateRegistry(this.urlMatcherFactory, this.urlRouterProvider);
3939

4040
// TODO: move this to ng1.ts
4141
stateProvider = new StateProvider(this.stateRegistry);

src/state/stateRegistry.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class StateRegistry {
1717
private builder: StateBuilder;
1818
stateQueue: StateQueueManager;
1919

20-
constructor(urlMatcherFactory: UrlMatcherFactory, urlRouterProvider, private currentState: () => State) {
20+
constructor(urlMatcherFactory: UrlMatcherFactory, urlRouterProvider) {
2121
this.matcher = new StateMatcher(this.states);
2222
this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
2323
this.stateQueue = new StateQueueManager(this.states, this.builder, urlRouterProvider);
@@ -44,9 +44,12 @@ export class StateRegistry {
4444
return this.stateQueue.register(stateDefinition);
4545
}
4646

47-
get(stateOrName: StateOrName, base: StateOrName): (StateDeclaration|StateDeclaration[]) {
48-
if (arguments.length === 0) return Object.keys(this.states).map(name => this.states[name].self);
49-
let found = this.matcher.find(stateOrName, base || this.currentState());
47+
get(): StateDeclaration[];
48+
get(stateOrName: StateOrName, base: StateOrName): StateDeclaration;
49+
get(stateOrName?: StateOrName, base?: StateOrName): (StateDeclaration|StateDeclaration[]) {
50+
if (arguments.length === 0)
51+
return <StateDeclaration[]> Object.keys(this.states).map(name => this.states[name].self);
52+
let found = this.matcher.find(stateOrName, base);
5053
return found && found.self || null;
5154
}
5255

src/state/stateService.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ export class StateService {
472472
* @param {string|object=} base When stateOrName is a relative state reference, the state will be retrieved relative to context.
473473
* @returns {Object|Array} State configuration object or array of all objects.
474474
*/
475-
get(stateOrName: StateOrName, base: StateOrName) {
476-
return this.stateRegistry.get.apply(this.stateRegistry, arguments);
475+
get(): StateDeclaration[];
476+
get(stateOrName: StateOrName, base: StateOrName): StateDeclaration;
477+
get(stateOrName?: StateOrName, base?: StateOrName): (StateDeclaration|StateDeclaration[]) {
478+
if (arguments.length === 0) return this.stateRegistry.get();
479+
return this.stateRegistry.get(stateOrName, base || this.$current);
477480
}
478481
}

0 commit comments

Comments
 (0)