@canlooks/statio 1.0.1 → 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/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();
|