Skip to content

Commit

Permalink
BREAKING CHANGE: Replace UrlRouterProvider/UrlRouter with just UrlRouter
Browse files Browse the repository at this point in the history
The configuration functions from the provider object have been integrated into the normal UrlRouter object.
The `UIRouter` object no longer has a `uriRouterProvider`, but the equivalent functions can be found on `uiRouter`

One difference between the old functions on `urlRouterProvider` and the new ones on `uriRouter` is that new functions do not accept injectable functions.
  • Loading branch information
christopherthielen committed Dec 22, 2016
1 parent 6c3ce5a commit fddd1e2
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 264 deletions.
7 changes: 2 additions & 5 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module core
*/ /** */
import { UrlMatcherFactory } from "./url/urlMatcherFactory";
import { UrlRouterProvider, UrlRouter } from "./url/urlRouter";
import { UrlRouter } from "./url/urlRouter";
import { TransitionService } from "./transition/transitionService";
import { ViewService } from "./view/view";
import { StateRegistry } from "./state/stateRegistry";
Expand Down Expand Up @@ -41,11 +41,9 @@ export class UIRouter {

urlMatcherFactory: UrlMatcherFactory = new UrlMatcherFactory();

urlRouterProvider: UrlRouterProvider = new UrlRouterProvider(this);

urlRouter: UrlRouter = new UrlRouter(this);

stateRegistry: StateRegistry = new StateRegistry(this.urlMatcherFactory, this.urlRouterProvider);
stateRegistry: StateRegistry = new StateRegistry(this);

stateService = new StateService(this);

Expand Down Expand Up @@ -92,7 +90,6 @@ export class UIRouter {
this.globals.current = this.globals.$current.self;

this.disposable(this.transitionService);
this.disposable(this.urlRouterProvider);
this.disposable(this.urlRouter);
this.disposable(this.stateRegistry);
this.disposable(locationService);
Expand Down
14 changes: 7 additions & 7 deletions src/state/stateQueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import { isString } from "../common/predicates";
import { StateDeclaration } from "./interface";
import { State } from "./stateObject";
import { StateBuilder } from "./stateBuilder";
import { UrlRouterProvider } from "../url/urlRouter";
import { StateRegistry, StateRegistryListener } from "./stateRegistry";
import { StateRegistryListener, StateRegistry } from "./stateRegistry";
import { Disposable } from "../interface";
import { UrlRuleFactory } from "../url/urlRule";
import { UrlRouter } from "../url/urlRouter";

/** @internalapi */
export class StateQueueManager implements Disposable {
queue: State[];

constructor(
private $registry: StateRegistry,
private $urlRouter: UrlRouter,
public states: { [key: string]: State; },
public $registry: StateRegistry,
public builder: StateBuilder,
public $urlRouterProvider: UrlRouterProvider,
public listeners: StateRegistryListener[]) {
this.queue = [];
}
Expand Down Expand Up @@ -100,7 +99,8 @@ export class StateQueueManager implements Disposable {

attachRoute(state: State) {
if (state.abstract || !state.url) return;
state._urlRule = new UrlRuleFactory(this.$urlRouterProvider._router).fromState(state);
this.$urlRouterProvider.addRule(state._urlRule);

state._urlRule = this.$urlRouter.urlRuleFactory.fromState(state);
this.$urlRouter.addRule(state._urlRule);
}
}
19 changes: 13 additions & 6 deletions src/state/stateRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { State } from "./stateObject";
import { StateMatcher } from "./stateMatcher";
import { StateBuilder } from "./stateBuilder";
import { StateQueueManager } from "./stateQueueManager";
import { UrlMatcherFactory } from "../url/urlMatcherFactory";
import { StateDeclaration } from "./interface";
import { BuilderFunction } from "./stateBuilder";
import { StateOrName } from "./interface";
import { UrlRouterProvider } from "../url/urlRouter";
import { UrlRouter } from "../url/urlRouter";
import { removeFrom } from "../common/common";
import { UIRouter } from "../router";

/**
* The signature for the callback function provided to [[StateRegistry.onStateRegistryEvent]].
Expand All @@ -31,14 +31,21 @@ export class StateRegistry {
matcher: StateMatcher;
private builder: StateBuilder;
stateQueue: StateQueueManager;
urlRouter: UrlRouter;

listeners: StateRegistryListener[] = [];

constructor(urlMatcherFactory: UrlMatcherFactory, private urlRouterProvider: UrlRouterProvider) {
/** @internalapi */
constructor(private _router: UIRouter) {
this.urlRouter = _router.urlRouter;
this.matcher = new StateMatcher(this.states);
this.builder = new StateBuilder(this.matcher, urlMatcherFactory);
this.stateQueue = new StateQueueManager(this.states, this, this.builder, urlRouterProvider, this.listeners);
this.builder = new StateBuilder(this.matcher, _router.urlMatcherFactory);
this.stateQueue = new StateQueueManager(this, _router.urlRouter, this.states, this.builder, this.listeners);
this._registerRoot();
}

/** @internalapi */
private _registerRoot() {
let rootStateDef: StateDeclaration = {
name: '',
url: '^',
Expand Down Expand Up @@ -139,7 +146,7 @@ export class StateRegistry {
let deregistered = [state].concat(children).reverse();

deregistered.forEach(state => {
this.urlRouterProvider.removeRule(state._urlRule);
this.urlRouter.removeRule(state._urlRule);
delete this.states[state.name];
});

Expand Down
Loading

0 comments on commit fddd1e2

Please sign in to comment.