juststore 0.0.6 → 0.0.7
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/impl.d.ts +11 -1
- package/dist/impl.js +16 -4
- package/dist/node.js +7 -1
- package/package.json +2 -2
package/dist/impl.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { FieldPath, FieldPathValue, FieldValues } from './path';
|
|
2
|
-
export { getNestedValue, getSnapshot, joinPath, notifyListeners, produce, setLeaf, useDebounce, useObject, useSubscribe };
|
|
2
|
+
export { getNestedValue, getSnapshot, isClass, isEqual, joinPath, notifyListeners, produce, setLeaf, useDebounce, useObject, useSubscribe };
|
|
3
|
+
declare function isClass(value: unknown): boolean;
|
|
4
|
+
/** Compare two values for equality
|
|
5
|
+
* @description
|
|
6
|
+
* - react-fast-compare for non-class instances
|
|
7
|
+
* - reference equality for class instances
|
|
8
|
+
* @param a - The first value to compare
|
|
9
|
+
* @param b - The second value to compare
|
|
10
|
+
* @returns True if the values are equal, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
declare function isEqual(a: unknown, b: unknown): boolean;
|
|
3
13
|
/**
|
|
4
14
|
* Joins a namespace and path into a full key string.
|
|
5
15
|
*
|
package/dist/impl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import rfcIsEqual from 'react-fast-compare';
|
|
3
3
|
import { localStorageDelete, localStorageGet, localStorageSet } from './local_storage';
|
|
4
|
-
export { getNestedValue, getSnapshot, joinPath, notifyListeners, produce, setLeaf, useDebounce, useObject, useSubscribe };
|
|
4
|
+
export { getNestedValue, getSnapshot, isClass, isEqual, joinPath, notifyListeners, produce, setLeaf, useDebounce, useObject, useSubscribe };
|
|
5
5
|
const memoryStore = new Map();
|
|
6
6
|
// check if the value is a class instance
|
|
7
7
|
function isClass(value) {
|
|
@@ -19,6 +19,19 @@ function isClass(value) {
|
|
|
19
19
|
}
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
|
+
/** Compare two values for equality
|
|
23
|
+
* @description
|
|
24
|
+
* - react-fast-compare for non-class instances
|
|
25
|
+
* - reference equality for class instances
|
|
26
|
+
* @param a - The first value to compare
|
|
27
|
+
* @param b - The second value to compare
|
|
28
|
+
* @returns True if the values are equal, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
function isEqual(a, b) {
|
|
31
|
+
if (isClass(a) || isClass(b))
|
|
32
|
+
return a === b;
|
|
33
|
+
return rfcIsEqual(a, b);
|
|
34
|
+
}
|
|
22
35
|
/**
|
|
23
36
|
* Joins a namespace and path into a full key string.
|
|
24
37
|
*
|
|
@@ -375,8 +388,7 @@ function produce(key, value, skipUpdate = false, memoryOnly = false) {
|
|
|
375
388
|
store.delete(key, memoryOnly);
|
|
376
389
|
}
|
|
377
390
|
else {
|
|
378
|
-
|
|
379
|
-
if (useRefEquality ? current === value : isEqual(current, value))
|
|
391
|
+
if (isEqual(current, value))
|
|
380
392
|
return;
|
|
381
393
|
store.set(key, value, memoryOnly);
|
|
382
394
|
}
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
+
import { isEqual } from './impl';
|
|
3
4
|
export { createNode, createRootNode };
|
|
4
5
|
/**
|
|
5
6
|
* Creates the root proxy node for dynamic path access.
|
|
@@ -74,7 +75,12 @@ function createNode(storeApi, path, cache, extensions, from = unchanged, to = un
|
|
|
74
75
|
return (fn) => {
|
|
75
76
|
const initialValue = from(storeApi.value(path));
|
|
76
77
|
const [computedValue, setComputedValue] = useState(() => fn(initialValue));
|
|
77
|
-
storeApi.subscribe(path, value =>
|
|
78
|
+
storeApi.subscribe(path, value => {
|
|
79
|
+
const newValue = fn(from(value));
|
|
80
|
+
if (!isEqual(computedValue, newValue)) {
|
|
81
|
+
setComputedValue(newValue);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
return computedValue;
|
|
79
85
|
};
|
|
80
86
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juststore",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "A small, expressive, and type-safe state management library for React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "Yusing",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/yusing/juststore"
|
|
11
|
+
"url": "git+https://github.com/yusing/juststore.git"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/yusing/juststore",
|
|
14
14
|
"bugs": {
|