@figliolia/galena 1.0.0 → 2.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/README.md +17 -17
- package/dist/Galena/Galena.d.ts +13 -13
- package/dist/Galena/Galena.js +14 -14
- package/dist/Galena/State.d.ts +3 -3
- package/dist/Galena/State.js +3 -3
- package/dist/Galena/types.d.ts +1 -1
- package/package.json +2 -2
- package/src/Galena/Galena.ts +15 -15
- package/src/Galena/State.ts +7 -4
- package/src/Galena/types.ts +1 -1
package/README.md
CHANGED
|
@@ -7,9 +7,9 @@ In Galena, your state architecture is a composition of reactive units that can b
|
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
```bash
|
|
10
|
-
npm install --save galena
|
|
10
|
+
npm install --save @figliolia/galena
|
|
11
11
|
# or
|
|
12
|
-
yarn add galena
|
|
12
|
+
yarn add @figliolia/galena
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Composing Your Application State
|
|
@@ -18,8 +18,8 @@ Creating a "global" application state begins with initializing a `Galena` instan
|
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
// AppState.ts
|
|
21
|
-
import { Galena, Logger, Profiler } from "galena";
|
|
22
|
-
import type { Middleware } from "galena";
|
|
21
|
+
import { Galena, Logger, Profiler } from "@figliolia/galena";
|
|
22
|
+
import type { Middleware } from "@figliolia/galena";
|
|
23
23
|
|
|
24
24
|
const middleware: Middleware[] = [];
|
|
25
25
|
|
|
@@ -54,7 +54,7 @@ Creating units of state using `AppState.composeState()` will scope your new unit
|
|
|
54
54
|
// BusinessLogic.ts
|
|
55
55
|
import { AppState } from "./AppState.ts";
|
|
56
56
|
|
|
57
|
-
const subscription = AppState.subscribe("navigation",
|
|
57
|
+
const subscription = AppState.subscribe("navigation", state => {
|
|
58
58
|
// React to changes to Navigation state
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -93,7 +93,7 @@ Running mutations on individual units of state will automatically update your `G
|
|
|
93
93
|
You may also create units of state that are *not* connected to a "global" `Galena` instance. To promote flexibility for developers to organize their state however they wish, `Galena` exports its `State` object for usage directly:
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
|
-
import { State } from "galena";
|
|
96
|
+
import { State } from "@figliolia/galena";
|
|
97
97
|
|
|
98
98
|
// Create Your Isolated Unit of State
|
|
99
99
|
const FeatureState = new State("myFeature", {
|
|
@@ -127,8 +127,8 @@ In `Galena`, your "global" application state exists in the form of operable sub-
|
|
|
127
127
|
#### Galena Public Methods
|
|
128
128
|
|
|
129
129
|
```typescript
|
|
130
|
-
import { Galena, Logger, Profiler } from "galena";
|
|
131
|
-
import type { State } from "galena";
|
|
130
|
+
import { Galena, Logger, Profiler } from "@figliolia/galena";
|
|
131
|
+
import type { State } from "@figliolia/galena";
|
|
132
132
|
|
|
133
133
|
const AppState = new Galena(/* middleware */ [new Logger(), new Profiler()]);
|
|
134
134
|
|
|
@@ -217,7 +217,7 @@ AppState.unsubscribeAll(subscription);
|
|
|
217
217
|
While instances of `Galena` behave as a container for units of state, the `State` interface serves as the unit itself. The `State` interface has a predictable API designed to make composing your states simple and effective. Whether you compose your state using a "global" state or island architecture, the underlying API for your units of state look like the following:
|
|
218
218
|
|
|
219
219
|
```typescript
|
|
220
|
-
import { State, Logger, Profiler } from "galena";
|
|
220
|
+
import { State, Logger, Profiler } from "@figliolia/galena";
|
|
221
221
|
|
|
222
222
|
const MyState = new State(/* a unique name */ "myState", /* initial state */);
|
|
223
223
|
|
|
@@ -332,7 +332,7 @@ Galena supports developers creating enhancements for their usage of `Galena`. Ou
|
|
|
332
332
|
Galena comes with a redux-style state transition logger that prints to the console each time state updates. The Logger will log the previous state, the current state, and tell you which unit of `State` has changed.
|
|
333
333
|
|
|
334
334
|
```typescript
|
|
335
|
-
import { Galena, Logger } from "galena";
|
|
335
|
+
import { Galena, Logger } from "@figliolia/galena";
|
|
336
336
|
|
|
337
337
|
// Enable logging!
|
|
338
338
|
const AppState = new Galena([new Logger()]);
|
|
@@ -342,7 +342,7 @@ const AppState = new Galena([new Logger()]);
|
|
|
342
342
|
Galena also comes with a Profiler that can track the duration of all state transitions. When a state transition exceeds 16ms, a warning is printed to the console notifying the developer of a potential bottleneck in his or her application. By default the Profiler will log each time a state transition exceeds one full frame (16ms). This threshold can be adjusted by calling `new Profiler(/* any number of milliseconds */)`
|
|
343
343
|
|
|
344
344
|
```typescript
|
|
345
|
-
import { Galena, Profiler } from "galena";
|
|
345
|
+
import { Galena, Profiler } from "@figliolia/galena";
|
|
346
346
|
|
|
347
347
|
const AppState = new Galena([new Profiler()]);
|
|
348
348
|
```
|
|
@@ -353,7 +353,7 @@ Similar to a lot of stateful tools, `Galena` also exposes an API for creating yo
|
|
|
353
353
|
#### Applying Middleware
|
|
354
354
|
When applying middleware in `Galena`, you may choose to apply your middleware to *all* of your application state or just some of it. To apply middleware to each of your units of `State`, you can simply initialize `Galena` with the middleware that you enjoy using:
|
|
355
355
|
```typescript
|
|
356
|
-
import { Galena, Profiler, Logger } from "galena";
|
|
356
|
+
import { Galena, Profiler, Logger } from "@figliolia/galena";
|
|
357
357
|
|
|
358
358
|
export const AppState = new Galena([new Profiler(), new Logger()]);
|
|
359
359
|
```
|
|
@@ -362,7 +362,7 @@ Using this method, whenever you create a new unit of state using `AppState.compo
|
|
|
362
362
|
Alternatively, you may also choose to register a middleware on only some of your state:
|
|
363
363
|
|
|
364
364
|
```typescript
|
|
365
|
-
import { Galena, Profiler, Logger } from "galena";
|
|
365
|
+
import { Galena, Profiler, Logger } from "@figliolia/galena";
|
|
366
366
|
|
|
367
367
|
// Let's add logging to all of our units of State
|
|
368
368
|
export const AppState = new Galena([new Logger()]);
|
|
@@ -394,7 +394,7 @@ export const CurrentUserState = AppState.composeState("currentUser", {
|
|
|
394
394
|
Next, let's create our own custom middleware for ensuring that all entries in the `connectedUsers` array are strings:
|
|
395
395
|
|
|
396
396
|
```typescript
|
|
397
|
-
import { Middleware } from "galena";
|
|
397
|
+
import { Middleware } from "@figliolia/galena";
|
|
398
398
|
|
|
399
399
|
// Let's extend the Middleware class from the Galena library
|
|
400
400
|
export class ConnectedUsersMiddleware extends Middleware {
|
|
@@ -429,7 +429,7 @@ export class ConnectedUsersMiddleware extends Middleware {
|
|
|
429
429
|
|
|
430
430
|
Next let's bring this middleware into our application!
|
|
431
431
|
```typescript
|
|
432
|
-
import { State } from "galena";
|
|
432
|
+
import { State } from "@figliolia/galena";
|
|
433
433
|
import { ConnectedUsersMiddleware } from "./ConnectedUsersMiddleware";
|
|
434
434
|
|
|
435
435
|
export const CurrentUserState = AppState.composeState("currentUser", {
|
|
@@ -453,7 +453,7 @@ Galena's `State` interface is designed to be an out-of-the-box solution for hous
|
|
|
453
453
|
##### Creating State Models
|
|
454
454
|
```typescript
|
|
455
455
|
// UserModel.ts
|
|
456
|
-
import { State } from "galena";
|
|
456
|
+
import { State } from "@figliolia/galena";
|
|
457
457
|
|
|
458
458
|
// Let's extend the `State` class for a hypothetical
|
|
459
459
|
// user schema
|
|
@@ -480,7 +480,7 @@ Next, let's use our Model!
|
|
|
480
480
|
|
|
481
481
|
```typescript
|
|
482
482
|
// AppState.ts
|
|
483
|
-
import { Galena, State } from "galena";
|
|
483
|
+
import { Galena, State } from "@figliolia/galena";
|
|
484
484
|
import { UserModel } from "./UserModel";
|
|
485
485
|
|
|
486
486
|
export const AppState = new Galena(/* middleware */);
|
package/dist/Galena/Galena.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { State } from "./State";
|
|
|
9
9
|
*
|
|
10
10
|
* ```typescript
|
|
11
11
|
* // AppState.ts
|
|
12
|
-
* import { Galena } from "
|
|
12
|
+
* import { Galena } from "@figliolia/galena";
|
|
13
13
|
*
|
|
14
14
|
* const AppState = new Galena([...middleware]);
|
|
15
15
|
*
|
|
@@ -26,32 +26,32 @@ import { State } from "./State";
|
|
|
26
26
|
* import { AppState } from "./AppState";
|
|
27
27
|
*
|
|
28
28
|
* AppState.subscribe(appState => {
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* const navState = appState.get("navigation");
|
|
30
|
+
* const { currentRoute } = navState.state;
|
|
31
|
+
* // do something with state changes!
|
|
32
32
|
* });
|
|
33
33
|
* ```
|
|
34
34
|
* #### Using the State Instance
|
|
35
35
|
* ```typescript
|
|
36
36
|
* NavigationState.subscribe(navigation => {
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* const { currentRoute } = navigation
|
|
38
|
+
* // do something with state changes!
|
|
39
39
|
* });
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* #### Using Global Subscriptions
|
|
43
43
|
* ```typescript
|
|
44
|
-
* NavigationState.subscribeAll(
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* NavigationState.subscribeAll(nextState => {
|
|
45
|
+
* const { currentRoute } = nextState.navigation
|
|
46
|
+
* // do something with state changes!
|
|
47
47
|
* });
|
|
48
48
|
* ```
|
|
49
49
|
*
|
|
50
50
|
* ### Mutating State
|
|
51
51
|
* ```typescript
|
|
52
52
|
* NavigationState.update(state => {
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* state.currentRoute = "/profile";
|
|
54
|
+
* // You can mutate state without creating new objects!
|
|
55
55
|
* });
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
@@ -113,7 +113,7 @@ export declare class Galena<T extends Record<string, State<any>> = Record<string
|
|
|
113
113
|
* subscription, call `Galena.unsubscribe()` with the ID returned
|
|
114
114
|
* by this method
|
|
115
115
|
*/
|
|
116
|
-
subscribe<K extends keyof T>(name: K,
|
|
116
|
+
subscribe<K extends keyof T>(name: K, callback: Parameters<T[K]["subscribe"]>["0"]): string;
|
|
117
117
|
/**
|
|
118
118
|
* Unsubscribe
|
|
119
119
|
*
|
|
@@ -132,7 +132,7 @@ export declare class Galena<T extends Record<string, State<any>> = Record<string
|
|
|
132
132
|
* subscription, call `Galena.unsubscribeAll()` with the ID
|
|
133
133
|
* returned
|
|
134
134
|
*/
|
|
135
|
-
subscribeAll(callback: (
|
|
135
|
+
subscribeAll(callback: (nextState: T) => void): string;
|
|
136
136
|
/**
|
|
137
137
|
* Unsubscribe
|
|
138
138
|
*
|
package/dist/Galena/Galena.js
CHANGED
|
@@ -12,7 +12,7 @@ const State_1 = require("./State");
|
|
|
12
12
|
*
|
|
13
13
|
* ```typescript
|
|
14
14
|
* // AppState.ts
|
|
15
|
-
* import { Galena } from "
|
|
15
|
+
* import { Galena } from "@figliolia/galena";
|
|
16
16
|
*
|
|
17
17
|
* const AppState = new Galena([...middleware]);
|
|
18
18
|
*
|
|
@@ -29,32 +29,32 @@ const State_1 = require("./State");
|
|
|
29
29
|
* import { AppState } from "./AppState";
|
|
30
30
|
*
|
|
31
31
|
* AppState.subscribe(appState => {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* const navState = appState.get("navigation");
|
|
33
|
+
* const { currentRoute } = navState.state;
|
|
34
|
+
* // do something with state changes!
|
|
35
35
|
* });
|
|
36
36
|
* ```
|
|
37
37
|
* #### Using the State Instance
|
|
38
38
|
* ```typescript
|
|
39
39
|
* NavigationState.subscribe(navigation => {
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* const { currentRoute } = navigation
|
|
41
|
+
* // do something with state changes!
|
|
42
42
|
* });
|
|
43
43
|
* ```
|
|
44
44
|
*
|
|
45
45
|
* #### Using Global Subscriptions
|
|
46
46
|
* ```typescript
|
|
47
|
-
* NavigationState.subscribeAll(
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* NavigationState.subscribeAll(nextState => {
|
|
48
|
+
* const { currentRoute } = nextState.navigation
|
|
49
|
+
* // do something with state changes!
|
|
50
50
|
* });
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
53
|
* ### Mutating State
|
|
54
54
|
* ```typescript
|
|
55
55
|
* NavigationState.update(state => {
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* state.currentRoute = "/profile";
|
|
57
|
+
* // You can mutate state without creating new objects!
|
|
58
58
|
* });
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
@@ -136,8 +136,8 @@ class Galena {
|
|
|
136
136
|
* subscription, call `Galena.unsubscribe()` with the ID returned
|
|
137
137
|
* by this method
|
|
138
138
|
*/
|
|
139
|
-
subscribe(name,
|
|
140
|
-
return this.get(name).subscribe(
|
|
139
|
+
subscribe(name, callback) {
|
|
140
|
+
return this.get(name).subscribe(callback);
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Unsubscribe
|
|
@@ -166,7 +166,7 @@ class Galena {
|
|
|
166
166
|
stateSubscriptions.push([
|
|
167
167
|
key,
|
|
168
168
|
this.state[key].subscribe(() => {
|
|
169
|
-
callback(this);
|
|
169
|
+
callback(this.state);
|
|
170
170
|
}),
|
|
171
171
|
]);
|
|
172
172
|
}
|
package/dist/Galena/State.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ import { Scheduler } from "./Scheduler";
|
|
|
50
50
|
*
|
|
51
51
|
* #### Subscribing to State Changes
|
|
52
52
|
* ```typescript
|
|
53
|
-
* MyState.subscribe((
|
|
53
|
+
* MyState.subscribe((state) => {
|
|
54
54
|
* const { listItems } = state
|
|
55
55
|
* // Do something with your list items!
|
|
56
56
|
* });
|
|
@@ -162,7 +162,7 @@ export declare class State<T extends any = any> extends Scheduler {
|
|
|
162
162
|
* state
|
|
163
163
|
*
|
|
164
164
|
* ```typescript
|
|
165
|
-
* import { State } from "
|
|
165
|
+
* import { State } from "@figliolia/galena";
|
|
166
166
|
*
|
|
167
167
|
* // Extend of Galena State
|
|
168
168
|
* class MyState extends State {
|
|
@@ -200,7 +200,7 @@ export declare class State<T extends any = any> extends Scheduler {
|
|
|
200
200
|
* callback you provide will execute each time state changes.
|
|
201
201
|
* Returns a unique identifier for your subscription
|
|
202
202
|
*/
|
|
203
|
-
subscribe(callback: (nextState:
|
|
203
|
+
subscribe(callback: (nextState: T) => void): string;
|
|
204
204
|
/**
|
|
205
205
|
* Unsubscribe
|
|
206
206
|
*
|
package/dist/Galena/State.js
CHANGED
|
@@ -54,7 +54,7 @@ const Scheduler_1 = require("./Scheduler");
|
|
|
54
54
|
*
|
|
55
55
|
* #### Subscribing to State Changes
|
|
56
56
|
* ```typescript
|
|
57
|
-
* MyState.subscribe((
|
|
57
|
+
* MyState.subscribe((state) => {
|
|
58
58
|
* const { listItems } = state
|
|
59
59
|
* // Do something with your list items!
|
|
60
60
|
* });
|
|
@@ -178,7 +178,7 @@ class State extends Scheduler_1.Scheduler {
|
|
|
178
178
|
* state
|
|
179
179
|
*
|
|
180
180
|
* ```typescript
|
|
181
|
-
* import { State } from "
|
|
181
|
+
* import { State } from "@figliolia/galena";
|
|
182
182
|
*
|
|
183
183
|
* // Extend of Galena State
|
|
184
184
|
* class MyState extends State {
|
|
@@ -216,7 +216,7 @@ class State extends Scheduler_1.Scheduler {
|
|
|
216
216
|
*/
|
|
217
217
|
scheduleUpdate(priority) {
|
|
218
218
|
this.lifeCycleEvent(types_1.MiddlewareEvents.onUpdate);
|
|
219
|
-
void this.scheduleTask(() => this.emitter.emit(this.name, this), priority);
|
|
219
|
+
void this.scheduleTask(() => this.emitter.emit(this.name, this.state), priority);
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
222
|
* Register Middleware
|
package/dist/Galena/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figliolia/galena",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A performant state management library supporting mutable state, batched updates, middleware and a rich development API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"lint": "tsc --noemit && eslint ./ --fix"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@figliolia/event-emitter": "^1.0.
|
|
37
|
+
"@figliolia/event-emitter": "^1.0.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^16.7.13",
|
package/src/Galena/Galena.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { State } from "Galena/State";
|
|
|
13
13
|
*
|
|
14
14
|
* ```typescript
|
|
15
15
|
* // AppState.ts
|
|
16
|
-
* import { Galena } from "galena";
|
|
16
|
+
* import { Galena } from "@figliolia/galena";
|
|
17
17
|
*
|
|
18
18
|
* const AppState = new Galena([...middleware]);
|
|
19
19
|
*
|
|
@@ -30,32 +30,32 @@ import { State } from "Galena/State";
|
|
|
30
30
|
* import { AppState } from "./AppState";
|
|
31
31
|
*
|
|
32
32
|
* AppState.subscribe(appState => {
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* const navState = appState.get("navigation");
|
|
34
|
+
* const { currentRoute } = navState.state;
|
|
35
|
+
* // do something with state changes!
|
|
36
36
|
* });
|
|
37
37
|
* ```
|
|
38
38
|
* #### Using the State Instance
|
|
39
39
|
* ```typescript
|
|
40
40
|
* NavigationState.subscribe(navigation => {
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* const { currentRoute } = navigation
|
|
42
|
+
* // do something with state changes!
|
|
43
43
|
* });
|
|
44
44
|
* ```
|
|
45
45
|
*
|
|
46
46
|
* #### Using Global Subscriptions
|
|
47
47
|
* ```typescript
|
|
48
|
-
* NavigationState.subscribeAll(
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* NavigationState.subscribeAll(nextState => {
|
|
49
|
+
* const { currentRoute } = nextState.navigation
|
|
50
|
+
* // do something with state changes!
|
|
51
51
|
* });
|
|
52
52
|
* ```
|
|
53
53
|
*
|
|
54
54
|
* ### Mutating State
|
|
55
55
|
* ```typescript
|
|
56
56
|
* NavigationState.update(state => {
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* state.currentRoute = "/profile";
|
|
58
|
+
* // You can mutate state without creating new objects!
|
|
59
59
|
* });
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
@@ -166,9 +166,9 @@ export class Galena<
|
|
|
166
166
|
*/
|
|
167
167
|
public subscribe<K extends keyof T>(
|
|
168
168
|
name: K,
|
|
169
|
-
|
|
169
|
+
callback: Parameters<T[K]["subscribe"]>["0"]
|
|
170
170
|
) {
|
|
171
|
-
return this.get(name).subscribe(
|
|
171
|
+
return this.get(name).subscribe(callback);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
@@ -192,14 +192,14 @@ export class Galena<
|
|
|
192
192
|
* subscription, call `Galena.unsubscribeAll()` with the ID
|
|
193
193
|
* returned
|
|
194
194
|
*/
|
|
195
|
-
public subscribeAll(callback: (
|
|
195
|
+
public subscribeAll(callback: (nextState: T) => void) {
|
|
196
196
|
const subscriptionID = this.IDs.get();
|
|
197
197
|
const stateSubscriptions: [state: string, ID: string][] = [];
|
|
198
198
|
for (const key in this.state) {
|
|
199
199
|
stateSubscriptions.push([
|
|
200
200
|
key,
|
|
201
201
|
this.state[key].subscribe(() => {
|
|
202
|
-
callback(this);
|
|
202
|
+
callback(this.state);
|
|
203
203
|
}),
|
|
204
204
|
]);
|
|
205
205
|
}
|
package/src/Galena/State.ts
CHANGED
|
@@ -53,7 +53,7 @@ import { Scheduler } from "./Scheduler";
|
|
|
53
53
|
*
|
|
54
54
|
* #### Subscribing to State Changes
|
|
55
55
|
* ```typescript
|
|
56
|
-
* MyState.subscribe((
|
|
56
|
+
* MyState.subscribe((state) => {
|
|
57
57
|
* const { listItems } = state
|
|
58
58
|
* // Do something with your list items!
|
|
59
59
|
* });
|
|
@@ -195,7 +195,7 @@ export class State<T extends any = any> extends Scheduler {
|
|
|
195
195
|
* state
|
|
196
196
|
*
|
|
197
197
|
* ```typescript
|
|
198
|
-
* import { State } from "galena";
|
|
198
|
+
* import { State } from "@figliolia/galena";
|
|
199
199
|
*
|
|
200
200
|
* // Extend of Galena State
|
|
201
201
|
* class MyState extends State {
|
|
@@ -237,7 +237,10 @@ export class State<T extends any = any> extends Scheduler {
|
|
|
237
237
|
*/
|
|
238
238
|
private scheduleUpdate(priority: Priority) {
|
|
239
239
|
this.lifeCycleEvent(MiddlewareEvents.onUpdate);
|
|
240
|
-
void this.scheduleTask(
|
|
240
|
+
void this.scheduleTask(
|
|
241
|
+
() => this.emitter.emit(this.name, this.state),
|
|
242
|
+
priority
|
|
243
|
+
);
|
|
241
244
|
}
|
|
242
245
|
|
|
243
246
|
/**
|
|
@@ -257,7 +260,7 @@ export class State<T extends any = any> extends Scheduler {
|
|
|
257
260
|
* callback you provide will execute each time state changes.
|
|
258
261
|
* Returns a unique identifier for your subscription
|
|
259
262
|
*/
|
|
260
|
-
public subscribe(callback: (nextState:
|
|
263
|
+
public subscribe(callback: (nextState: T) => void) {
|
|
261
264
|
return this.emitter.on(this.name, callback);
|
|
262
265
|
}
|
|
263
266
|
|