coaction 1.5.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 +42 -6
- package/dist/index.d.mts +384 -306
- package/dist/index.d.ts +384 -306
- package/dist/index.js +1420 -1147
- package/dist/index.mjs +1327 -1130
- package/package.json +25 -24
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# coaction
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
[](https://www.npmjs.com/package/coaction)
|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
An efficient and flexible state management library for building high-performance, multithreading web applications.
|
|
8
8
|
|
|
9
|
+
Coaction 2.0 uses `alien-signals` internally for cached getter/computed state,
|
|
10
|
+
React selector reactivity, and adapter-facing subscriptions. The core package
|
|
11
|
+
also re-exports the signal primitives for advanced integrations.
|
|
12
|
+
|
|
9
13
|
## Installation
|
|
10
14
|
|
|
11
15
|
You can install it via npm, yarn or pnpm.
|
|
@@ -19,12 +23,44 @@ npm install coaction
|
|
|
19
23
|
```jsx
|
|
20
24
|
import { create } from 'coaction';
|
|
21
25
|
|
|
22
|
-
const
|
|
26
|
+
const store = create((set) => ({
|
|
27
|
+
count: 0,
|
|
28
|
+
get doubleCount() {
|
|
29
|
+
return this.count * 2;
|
|
30
|
+
},
|
|
31
|
+
increment() {
|
|
32
|
+
set(() => {
|
|
33
|
+
this.count += 1;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Accessor getters are cached automatically through the built-in signal runtime.
|
|
40
|
+
Use `get(deps, selector)` when you want to declare dependencies manually:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const store = create((set, get) => ({
|
|
23
44
|
count: 0,
|
|
24
|
-
|
|
45
|
+
doubleCount: get(
|
|
46
|
+
(state) => [state.count],
|
|
47
|
+
(count) => count * 2
|
|
48
|
+
),
|
|
49
|
+
increment() {
|
|
50
|
+
set(() => {
|
|
51
|
+
this.count += 1;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
25
54
|
}));
|
|
26
55
|
```
|
|
27
56
|
|
|
57
|
+
Advanced integrations can import the native signal primitives and adapter helper
|
|
58
|
+
directly from `coaction`:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { computed, defineExternalStoreAdapter, effect, signal } from 'coaction';
|
|
62
|
+
```
|
|
63
|
+
|
|
28
64
|
Store methods using `this` are rebound to the latest state when invoked from
|
|
29
65
|
`getState()`, so destructuring remains safe:
|
|
30
66
|
|
|
@@ -44,8 +80,8 @@ increment();
|
|
|
44
80
|
|
|
45
81
|
## API Reference
|
|
46
82
|
|
|
47
|
-
- [Generated core API index](https://github.com/
|
|
48
|
-
- [Core API notes](https://github.com/
|
|
83
|
+
- [Generated core API index](https://github.com/coactionjs/coaction/blob/main/docs/api/core/index.md)
|
|
84
|
+
- [Core API notes](https://github.com/coactionjs/coaction/blob/main/docs/api/core/documents/core-api-notes.md)
|
|
49
85
|
|
|
50
86
|
### Store Shape Mode (`sliceMode`)
|
|
51
87
|
|
|
@@ -67,4 +103,4 @@ create({ counter: (set) => ({ count: 0 }) }, { sliceMode: 'slices' });
|
|
|
67
103
|
|
|
68
104
|
## Documentation
|
|
69
105
|
|
|
70
|
-
You can find the documentation [here](https://github.com/
|
|
106
|
+
You can find the documentation [here](https://github.com/coactionjs/coaction).
|