coaction 0.1.1 → 0.1.5

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.
@@ -1,4 +1,5 @@
1
1
  import type { Store } from "./interface.js";
2
+ import { Internal } from "./internal.js";
2
3
  /**
3
4
  * createBinder is a function to create a binder for the 3rd party store.
4
5
  */
@@ -23,5 +24,5 @@ export declare function createBinder<F = (...args: any[]) => any>({ handleState,
23
24
  /**
24
25
  * handleStore is a function to handle the store object.
25
26
  */
26
- handleStore: (store: Store<object>, rawState: object, state: object) => void;
27
+ handleStore: (store: Store<object>, rawState: object, state: object, internal: Internal<object>) => void;
27
28
  }): F;
@@ -27,7 +27,7 @@ export interface Store<T extends ISlices = ISlices> {
27
27
  */
28
28
  getState: () => T;
29
29
  /**
30
- * Subscribe to the state changes.
30
+ * Subscribe to the state changes, and return the unsubscribe function.
31
31
  */
32
32
  subscribe: (listener: Listener) => () => void;
33
33
  /**
@@ -58,10 +58,6 @@ export interface Store<T extends ISlices = ISlices> {
58
58
  * Get the initial state.
59
59
  */
60
60
  getInitialState: () => T;
61
- /**
62
- * Get the raw instance via the initial state.
63
- */
64
- toRaw?: (key: any) => any;
65
61
  /**
66
62
  * The patch is used to update the state.
67
63
  */
@@ -72,10 +68,6 @@ export interface Store<T extends ISlices = ISlices> {
72
68
  patches: Patches;
73
69
  inversePatches: Patches;
74
70
  };
75
- /**
76
- * The act is used to run the function in the action.
77
- */
78
- act?: <T extends () => any>(fn: T) => ReturnType<T>;
79
71
  /**
80
72
  * The trace is used to trace the action
81
73
  */
@@ -0,0 +1,48 @@
1
+ import type { Draft, Patches } from 'mutative';
2
+ import type { CreateState, Listener } from "./interface.js";
3
+ export interface Internal<T extends CreateState = CreateState> {
4
+ /**
5
+ * The store module.
6
+ */
7
+ module: T;
8
+ /**
9
+ * The root state.
10
+ */
11
+ rootState: T | Draft<T>;
12
+ /**
13
+ * The backup state.
14
+ */
15
+ backupState: T | Draft<T>;
16
+ /**
17
+ * Finalize the draft.
18
+ */
19
+ finalizeDraft: () => [T, Patches, Patches];
20
+ /**
21
+ * The mutable instance.
22
+ */
23
+ mutableInstance: any;
24
+ /**
25
+ * The sequence number.
26
+ */
27
+ sequence: number;
28
+ /**
29
+ * Whether the batch is running.
30
+ */
31
+ isBatching: boolean;
32
+ /**
33
+ * The listeners.
34
+ */
35
+ listeners: Set<Listener>;
36
+ /**
37
+ * The act is used to run the function in the action for mutable state.
38
+ */
39
+ actMutable?: <T extends () => any>(fn: T) => ReturnType<T>;
40
+ /**
41
+ * Get the mutable raw instance via the initial state.
42
+ */
43
+ toMutableRaw?: (key: any) => any;
44
+ /**
45
+ * The update immutable function.
46
+ */
47
+ updateImmutable?: (state: T) => void;
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coaction",
3
- "version": "0.1.1",
3
+ "version": "0.1.5",
4
4
  "description": "A sleek JavaScript library designed for high-performance and multithreading web apps.",
5
5
  "keywords": [
6
6
  "coaction"
@@ -37,7 +37,6 @@
37
37
  "bugs": {
38
38
  "url": "https://github.com/unadlib/coaction/issues"
39
39
  },
40
- "devDependencies": {},
41
40
  "preconstruct": {
42
41
  "umdName": "Coaction",
43
42
  "entrypoints": [