Skip to content

Commit a794018

Browse files
feat(Globals): implement Disposable and delete global transition data
1 parent 408491b commit a794018

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/globals.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {Transition} from "./transition/transition";
99
import {Queue} from "./common/queue";
1010
import {TransitionService} from "./transition/transitionService";
1111
import {copy} from "./common/common";
12+
import { Disposable } from './interface';
1213

1314
/**
1415
* Global router state
1516
*
1617
* This is where we hold the global mutable state such as current state, current
1718
* params, current transition, etc.
1819
*/
19-
export class UIRouterGlobals {
20+
export class UIRouterGlobals implements Disposable {
2021
/**
2122
* Current parameter values
2223
*
@@ -49,4 +50,10 @@ export class UIRouterGlobals {
4950

5051
/** @internalapi */
5152
successfulTransitions = new Queue<Transition>([], 1);
53+
54+
dispose() {
55+
this.transitionHistory.clear();
56+
this.successfulTransitions.clear();
57+
this.transition = null;
58+
}
5259
}

src/router.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ export class UIRouter {
119119
this.globals.$current = this.stateRegistry.root();
120120
this.globals.current = this.globals.$current.self;
121121

122+
this.disposable(this.globals);
123+
this.disposable(this.stateService);
124+
this.disposable(this.stateRegistry);
122125
this.disposable(this.transitionService);
123126
this.disposable(this.urlRouter);
124-
this.disposable(this.stateRegistry);
125127
this.disposable(locationService);
126128
this.disposable(locationConfig);
127129
}

src/transition/transitionService.ts

-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ export class TransitionService implements IHookRegistry, Disposable {
207207
* @internalapi
208208
*/
209209
dispose(router: UIRouter) {
210-
delete router.globals.transition;
211-
212210
values(this._registeredHooks).forEach((hooksArray: RegisteredHook[]) => hooksArray.forEach(hook => {
213211
hook._deregistered = true;
214212
removeFrom(hooksArray, hook);

0 commit comments

Comments
 (0)