@dharmax/state-router 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/state-manager.d.ts +3 -2
- package/dist/state-manager.js +8 -3
- package/package.json +1 -1
- package/src/state-manager.ts +0 -1
package/dist/state-manager.d.ts
CHANGED
|
@@ -9,13 +9,15 @@ export type ApplicationState = {
|
|
|
9
9
|
};
|
|
10
10
|
export type ChangeAuthority = (state: ApplicationState) => Promise<boolean>;
|
|
11
11
|
export declare class StateManager {
|
|
12
|
+
private mode;
|
|
12
13
|
private allStates;
|
|
13
14
|
private appState;
|
|
14
15
|
private previousState;
|
|
15
16
|
private stateContext;
|
|
16
17
|
static dispatcher: import("@dharmax/pubsub").PubSub;
|
|
17
18
|
private changeAuthorities;
|
|
18
|
-
constructor(mode?: RoutingMode);
|
|
19
|
+
constructor(mode?: RoutingMode, autostart?: boolean);
|
|
20
|
+
start(): void;
|
|
19
21
|
onChange(handler: (event: PubSubEvent, data: any) => void): IPubSubHandle;
|
|
20
22
|
registerChangeAuthority(authorityCallback: (targetState: ApplicationState) => Promise<boolean>): void;
|
|
21
23
|
getState(): ApplicationState;
|
|
@@ -44,4 +46,3 @@ export declare class StateManager {
|
|
|
44
46
|
addState(name: string, pageName?: string, route?: RegExp | string, mode?: string | string[]): void;
|
|
45
47
|
registerStateByState(state: ApplicationState): void;
|
|
46
48
|
}
|
|
47
|
-
export declare const stateManager: StateManager;
|
package/dist/state-manager.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { router } from "./router";
|
|
2
2
|
import dispatcher from "@dharmax/pubsub";
|
|
3
3
|
export class StateManager {
|
|
4
|
+
mode;
|
|
4
5
|
allStates = {};
|
|
5
6
|
appState;
|
|
6
7
|
previousState;
|
|
7
8
|
stateContext;
|
|
8
9
|
static dispatcher = dispatcher;
|
|
9
10
|
changeAuthorities = [];
|
|
10
|
-
constructor(mode = 'hash') {
|
|
11
|
-
|
|
11
|
+
constructor(mode = 'hash', autostart = true) {
|
|
12
|
+
this.mode = mode;
|
|
13
|
+
if (autostart)
|
|
14
|
+
router.listen(mode);
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
router.listen(this.mode);
|
|
12
18
|
}
|
|
13
19
|
onChange(handler) {
|
|
14
20
|
return StateManager.dispatcher.on('state:changed', handler);
|
|
@@ -102,4 +108,3 @@ export class StateManager {
|
|
|
102
108
|
});
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
export const stateManager = new StateManager();
|
package/package.json
CHANGED
package/src/state-manager.ts
CHANGED