juststore 1.1.0 → 1.1.1
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 +17 -2
- package/package.json +61 -51
package/dist/root.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import { getNestedValue, getSnapshot, joinPath, notifyListeners, produce, rename, setLeaf, subscribe, useCompute, useDebounce, useObject } from './impl';
|
|
2
|
+
import { getNestedValue, getSnapshot, isRecord, joinPath, notifyListeners, produce, rename, setLeaf, subscribe, useCompute, useDebounce, useObject } from './impl';
|
|
3
3
|
import { createRootNode } from './node';
|
|
4
4
|
export { createStoreRoot };
|
|
5
5
|
/**
|
|
@@ -18,7 +18,7 @@ function createStoreRoot(namespace, defaultValue, options = {}) {
|
|
|
18
18
|
'use memo';
|
|
19
19
|
const memoryOnly = options?.memoryOnly ?? false;
|
|
20
20
|
// merge with default value and save in memory only
|
|
21
|
-
produce(namespace,
|
|
21
|
+
produce(namespace, mergeWithDefaults(defaultValue, getSnapshot(namespace, memoryOnly)), true, true);
|
|
22
22
|
const storeApi = {
|
|
23
23
|
state: (path) => createRootNode(storeApi, path),
|
|
24
24
|
use: (path) => useObject(namespace, path, memoryOnly),
|
|
@@ -64,3 +64,18 @@ function createStoreRoot(namespace, defaultValue, options = {}) {
|
|
|
64
64
|
};
|
|
65
65
|
return storeApi;
|
|
66
66
|
}
|
|
67
|
+
function mergeWithDefaults(defaultValue, existingValue) {
|
|
68
|
+
if (existingValue === undefined) {
|
|
69
|
+
return defaultValue;
|
|
70
|
+
}
|
|
71
|
+
if (!isRecord(defaultValue) || !isRecord(existingValue)) {
|
|
72
|
+
return existingValue;
|
|
73
|
+
}
|
|
74
|
+
const defaults = defaultValue;
|
|
75
|
+
const existing = existingValue;
|
|
76
|
+
const merged = { ...existing };
|
|
77
|
+
for (const key of Object.keys(defaults)) {
|
|
78
|
+
merged[key] = mergeWithDefaults(defaults[key], existing[key]);
|
|
79
|
+
}
|
|
80
|
+
return merged;
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,53 +1,63 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
2
|
+
"name": "juststore",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "A small, expressive, and type-safe state management library for React.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"author": "Yusing",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/yusing/juststore.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/yusing/juststore",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/yusing/juststore/issues"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"license": "AGPL-3.0-only",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"state",
|
|
30
|
+
"react",
|
|
31
|
+
"typescript",
|
|
32
|
+
"hooks",
|
|
33
|
+
"store",
|
|
34
|
+
"state management",
|
|
35
|
+
"react hooks"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "bun --bun tsc",
|
|
39
|
+
"typecheck": "bun --bun tsc --noEmit",
|
|
40
|
+
"lint": "biome check",
|
|
41
|
+
"format": "biome format --write",
|
|
42
|
+
"format:check": "biome format",
|
|
43
|
+
"prepublishOnly": "bun run build",
|
|
44
|
+
"publish": "npm publish --access public",
|
|
45
|
+
"prepare": "husky"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"change-case": "^5.4.4",
|
|
52
|
+
"react-fast-compare": "^3.2.2"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@biomejs/biome": "^2.4.6",
|
|
56
|
+
"@eslint/js": "^10.0.1",
|
|
57
|
+
"@types/node": "^25.4.0",
|
|
58
|
+
"@types/react": "^19.2.14",
|
|
59
|
+
"husky": "^9.1.7",
|
|
60
|
+
"react": "^19.2.4",
|
|
61
|
+
"typescript": "^5.9.3"
|
|
62
|
+
}
|
|
53
63
|
}
|