Skip to content

Commit

Permalink
feat(Globals): implement Disposable and delete global transition data
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Feb 23, 2017
1 parent 408491b commit a794018
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {Transition} from "./transition/transition";
import {Queue} from "./common/queue";
import {TransitionService} from "./transition/transitionService";
import {copy} from "./common/common";
import { Disposable } from './interface';

/**
* Global router state
*
* This is where we hold the global mutable state such as current state, current
* params, current transition, etc.
*/
export class UIRouterGlobals {
export class UIRouterGlobals implements Disposable {
/**
* Current parameter values
*
Expand Down Expand Up @@ -49,4 +50,10 @@ export class UIRouterGlobals {

/** @internalapi */
successfulTransitions = new Queue<Transition>([], 1);

dispose() {
this.transitionHistory.clear();
this.successfulTransitions.clear();
this.transition = null;
}
}
4 changes: 3 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ export class UIRouter {
this.globals.$current = this.stateRegistry.root();
this.globals.current = this.globals.$current.self;

this.disposable(this.globals);
this.disposable(this.stateService);
this.disposable(this.stateRegistry);
this.disposable(this.transitionService);
this.disposable(this.urlRouter);
this.disposable(this.stateRegistry);
this.disposable(locationService);
this.disposable(locationConfig);
}
Expand Down
2 changes: 0 additions & 2 deletions src/transition/transitionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ export class TransitionService implements IHookRegistry, Disposable {
* @internalapi
*/
dispose(router: UIRouter) {
delete router.globals.transition;

values(this._registeredHooks).forEach((hooksArray: RegisteredHook[]) => hooksArray.forEach(hook => {
hook._deregistered = true;
removeFrom(hooksArray, hook);
Expand Down

0 comments on commit a794018

Please sign in to comment.