juststore 0.1.0 → 0.1.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/root.js +3 -2
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/root.js
CHANGED
|
@@ -35,9 +35,10 @@ function createStoreRoot(namespace, defaultValue, options = {}) {
|
|
|
35
35
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
36
36
|
useSubscribe(joinPath(namespace, path), listener),
|
|
37
37
|
useCompute: (path, fn) => {
|
|
38
|
-
const
|
|
38
|
+
const fullPath = joinPath(namespace, path);
|
|
39
|
+
const initialValue = getSnapshot(fullPath);
|
|
39
40
|
const [computedValue, setComputedValue] = useState(() => fn(initialValue));
|
|
40
|
-
useSubscribe(
|
|
41
|
+
useSubscribe(fullPath, value => {
|
|
41
42
|
const newValue = fn(value);
|
|
42
43
|
if (!isEqual(computedValue, newValue)) {
|
|
43
44
|
setComputedValue(newValue);
|
package/dist/types.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ type StoreRoot<T extends FieldValues> = {
|
|
|
44
44
|
/** Subscribe to changes at path and invoke listener with the new value. */
|
|
45
45
|
subscribe: <P extends FieldPath<T>>(path: P, listener: (value: FieldPathValue<T, P>) => void) => void;
|
|
46
46
|
/** Compute a derived value from the current value, similar to useState + useMemo */
|
|
47
|
-
useCompute: <P extends FieldPath<T
|
|
47
|
+
useCompute: <P extends FieldPath<T>, R>(path: P, fn: (value: FieldPathValue<T, P>) => R) => R;
|
|
48
48
|
/** Notify listeners at path. */
|
|
49
49
|
notify: <P extends FieldPath<T>>(path: P) => void;
|
|
50
50
|
/** Convenience hook returning [value, setValue] for the path. */
|