@canlooks/statio 1.0.0 → 1.0.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.
- package/README.md +0 -16
- package/dist/cjs/createStore.js +2 -1
- package/dist/esm/createStore.js +2 -1
- package/index.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -490,22 +490,6 @@ Selectors are also fully typed — the return type is inferred from the selector
|
|
|
490
490
|
|
|
491
491
|
---
|
|
492
492
|
|
|
493
|
-
## Comparison
|
|
494
|
-
|
|
495
|
-
| Feature | Statio | Zustand | Jotai | Redux Toolkit |
|
|
496
|
-
|---------|--------|---------|-------|---------------|
|
|
497
|
-
| **Class-based stores** | ✅ | ❌ | ❌ | ❌ |
|
|
498
|
-
| **Computed properties** | ✅ (via `compute`) | ❌ (needs middleware) | ✅ (atoms) | ✅ (selectors) |
|
|
499
|
-
| **Built-in persistence** | ✅ (`storage`) | ✅ (`persist` middleware) | ✅ (`atomWithStorage`) | ❌ (needs middleware) |
|
|
500
|
-
| **Selective re-rendering** | ✅ (selector/shallowEqual) | ✅ (selector/shallow) | ✅ (atomic) | ✅ (selectors) |
|
|
501
|
-
| **Bundle size** | Tiny | Tiny | Small | Medium |
|
|
502
|
-
| **SSR support** | ✅ | ✅ | ✅ | ✅ |
|
|
503
|
-
| **Middleware system** | Wrapper pattern | Middleware API | N/A | Middleware API |
|
|
504
|
-
|
|
505
|
-
Statio is ideal when you want Zustand-like simplicity but prefer class-based organization, or need built-in computed properties without additional middleware.
|
|
506
|
-
|
|
507
|
-
---
|
|
508
|
-
|
|
509
493
|
## License
|
|
510
494
|
|
|
511
495
|
MIT
|
package/dist/cjs/createStore.js
CHANGED
|
@@ -36,6 +36,7 @@ function createStore(factory) {
|
|
|
36
36
|
if (selector) {
|
|
37
37
|
cachedSnapshot.current ||= selector(api.state);
|
|
38
38
|
}
|
|
39
|
+
const getSnapshot = () => selector ? cachedSnapshot.current : symbolHelper.current;
|
|
39
40
|
const result = (0, react_1.useSyncExternalStore)(onStoreChange => {
|
|
40
41
|
const listener = (snapshot) => {
|
|
41
42
|
if (selector) {
|
|
@@ -49,7 +50,7 @@ function createStore(factory) {
|
|
|
49
50
|
return selector
|
|
50
51
|
? subscribe(selector, listener, { isEqual, _initSnapshot: cachedSnapshot.current })
|
|
51
52
|
: subscribe(listener);
|
|
52
|
-
},
|
|
53
|
+
}, getSnapshot, () => api.serverState || getSnapshot());
|
|
53
54
|
return typeof result === 'symbol' ? api.state : result;
|
|
54
55
|
}
|
|
55
56
|
const listeners = new Set();
|
package/dist/esm/createStore.js
CHANGED
|
@@ -33,6 +33,7 @@ export function createStore(factory) {
|
|
|
33
33
|
if (selector) {
|
|
34
34
|
cachedSnapshot.current ||= selector(api.state);
|
|
35
35
|
}
|
|
36
|
+
const getSnapshot = () => selector ? cachedSnapshot.current : symbolHelper.current;
|
|
36
37
|
const result = useSyncExternalStore(onStoreChange => {
|
|
37
38
|
const listener = (snapshot) => {
|
|
38
39
|
if (selector) {
|
|
@@ -46,7 +47,7 @@ export function createStore(factory) {
|
|
|
46
47
|
return selector
|
|
47
48
|
? subscribe(selector, listener, { isEqual, _initSnapshot: cachedSnapshot.current })
|
|
48
49
|
: subscribe(listener);
|
|
49
|
-
},
|
|
50
|
+
}, getSnapshot, () => api.serverState || getSnapshot());
|
|
50
51
|
return typeof result === 'symbol' ? api.state : result;
|
|
51
52
|
}
|
|
52
53
|
const listeners = new Set();
|
package/index.d.ts
CHANGED
|
@@ -36,7 +36,11 @@ declare namespace Statio {
|
|
|
36
36
|
* createStore
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
function createStore<S extends object = any>(factory: StoreFactory<S> | StoreClass<S>):
|
|
39
|
+
function createStore<S extends object = any>(factory: StoreFactory<S> | StoreClass<S>): {
|
|
40
|
+
(): S
|
|
41
|
+
<K extends keyof S>(...keys: K[]): Pick<S, K>
|
|
42
|
+
<T = S>(selector: (state: S) => T, isEqual?: IsEqual<T>): T
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* ---------------------------------------------------------------------------------------
|