@dharmax/state-router 2.1.0 → 2.1.2

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.
@@ -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;
@@ -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
- router.listen(mode);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dharmax/state-router",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A cute and tight router and application state controller",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,10 +21,14 @@ export class StateManager {
21
21
  public static dispatcher = dispatcher
22
22
  private changeAuthorities: ChangeAuthority[] = [];
23
23
 
24
- constructor(mode: RoutingMode = 'hash') {
24
+ constructor(private mode: RoutingMode = 'hash', autostart= true) {
25
25
 
26
- router.listen(mode)
26
+ if (autostart)
27
+ router.listen(mode)
28
+ }
27
29
 
30
+ start() {
31
+ router.listen( this.mode )
28
32
  }
29
33
 
30
34
  onChange(handler: (event: PubSubEvent, data: any) => void): IPubSubHandle {