reactish-state 1.2.0 → 1.2.1-alpha.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.
|
@@ -9,26 +9,18 @@ const useSelector = (selectorParamFactory, deps) => {
|
|
|
9
9
|
const cutoff = items.length - 1;
|
|
10
10
|
const selectorFunc = items[cutoff];
|
|
11
11
|
items.length = cutoff;
|
|
12
|
-
const [context] = React.useState(() => (
|
|
13
|
-
sub: utils.createSubscriber(items)
|
|
14
|
-
}));
|
|
15
|
-
const get = () => {
|
|
16
|
-
const {
|
|
17
|
-
cache
|
|
18
|
-
} = context;
|
|
19
|
-
const selectorValues = utils.getSelectorValues(items);
|
|
20
|
-
const args = selectorValues.concat(deps || selectorFunc);
|
|
21
|
-
if (cache && utils.isEqual(args, cache.args)) return cache.val;
|
|
22
|
-
const val = selectorFunc(...selectorValues);
|
|
23
|
-
context.cache = {
|
|
24
|
-
args,
|
|
25
|
-
val
|
|
26
|
-
};
|
|
27
|
-
return val;
|
|
28
|
-
};
|
|
12
|
+
const [context] = React.useState(() => [utils.createSubscriber(items)]);
|
|
29
13
|
return useSnapshot.useSnapshot({
|
|
30
|
-
get
|
|
31
|
-
|
|
14
|
+
get: () => {
|
|
15
|
+
const cache = context[1];
|
|
16
|
+
const selectorValues = utils.getSelectorValues(items);
|
|
17
|
+
const args = selectorValues.concat(deps || selectorFunc);
|
|
18
|
+
if (cache && utils.isEqual(args, cache[0])) return cache[1];
|
|
19
|
+
const val = selectorFunc(...selectorValues);
|
|
20
|
+
context[1] = [args, val];
|
|
21
|
+
return val;
|
|
22
|
+
},
|
|
23
|
+
subscribe: context[0]
|
|
32
24
|
});
|
|
33
25
|
};
|
|
34
26
|
|
|
@@ -16,12 +16,9 @@ const createSelector = ({
|
|
|
16
16
|
const selector = {
|
|
17
17
|
get: () => {
|
|
18
18
|
const args = utils.getSelectorValues(items);
|
|
19
|
-
if (cache && utils.isEqual(args, cache
|
|
19
|
+
if (cache && utils.isEqual(args, cache[0])) return cache[1];
|
|
20
20
|
const val = selectorFunc(...args);
|
|
21
|
-
cache =
|
|
22
|
-
args,
|
|
23
|
-
val
|
|
24
|
-
};
|
|
21
|
+
cache = [args, val];
|
|
25
22
|
return val;
|
|
26
23
|
},
|
|
27
24
|
subscribe: utils.createSubscriber(items)
|
|
@@ -6,6 +6,13 @@ const createState = ({
|
|
|
6
6
|
let value = initialValue;
|
|
7
7
|
const listeners = new Set();
|
|
8
8
|
const get = () => value;
|
|
9
|
+
const readonlyState = {
|
|
10
|
+
get,
|
|
11
|
+
subscribe: listener => {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
return () => listeners.delete(listener);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
9
16
|
let set = newValue => {
|
|
10
17
|
const nextValue = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
11
18
|
if (!Object.is(value, nextValue)) {
|
|
@@ -14,20 +21,14 @@ const createState = ({
|
|
|
14
21
|
listeners.forEach(listener => listener(nextValue, prevValue));
|
|
15
22
|
}
|
|
16
23
|
};
|
|
17
|
-
const subscribe = listener => {
|
|
18
|
-
listeners.add(listener);
|
|
19
|
-
return () => listeners.delete(listener);
|
|
20
|
-
};
|
|
21
24
|
if (middleware) set = middleware({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
subscribe
|
|
25
|
+
...readonlyState,
|
|
26
|
+
set
|
|
25
27
|
}, config);
|
|
26
28
|
return {
|
|
27
29
|
...actionBuilder?.(set, get),
|
|
28
|
-
|
|
29
|
-
set
|
|
30
|
-
subscribe
|
|
30
|
+
...readonlyState,
|
|
31
|
+
set
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
const state = /*#__PURE__*/createState();
|
|
@@ -7,26 +7,18 @@ const useSelector = (selectorParamFactory, deps) => {
|
|
|
7
7
|
const cutoff = items.length - 1;
|
|
8
8
|
const selectorFunc = items[cutoff];
|
|
9
9
|
items.length = cutoff;
|
|
10
|
-
const [context] = useState(() => (
|
|
11
|
-
sub: createSubscriber(items)
|
|
12
|
-
}));
|
|
13
|
-
const get = () => {
|
|
14
|
-
const {
|
|
15
|
-
cache
|
|
16
|
-
} = context;
|
|
17
|
-
const selectorValues = getSelectorValues(items);
|
|
18
|
-
const args = selectorValues.concat(deps || selectorFunc);
|
|
19
|
-
if (cache && isEqual(args, cache.args)) return cache.val;
|
|
20
|
-
const val = selectorFunc(...selectorValues);
|
|
21
|
-
context.cache = {
|
|
22
|
-
args,
|
|
23
|
-
val
|
|
24
|
-
};
|
|
25
|
-
return val;
|
|
26
|
-
};
|
|
10
|
+
const [context] = useState(() => [createSubscriber(items)]);
|
|
27
11
|
return useSnapshot({
|
|
28
|
-
get
|
|
29
|
-
|
|
12
|
+
get: () => {
|
|
13
|
+
const cache = context[1];
|
|
14
|
+
const selectorValues = getSelectorValues(items);
|
|
15
|
+
const args = selectorValues.concat(deps || selectorFunc);
|
|
16
|
+
if (cache && isEqual(args, cache[0])) return cache[1];
|
|
17
|
+
const val = selectorFunc(...selectorValues);
|
|
18
|
+
context[1] = [args, val];
|
|
19
|
+
return val;
|
|
20
|
+
},
|
|
21
|
+
subscribe: context[0]
|
|
30
22
|
});
|
|
31
23
|
};
|
|
32
24
|
|
|
@@ -14,12 +14,9 @@ const createSelector = ({
|
|
|
14
14
|
const selector = {
|
|
15
15
|
get: () => {
|
|
16
16
|
const args = getSelectorValues(items);
|
|
17
|
-
if (cache && isEqual(args, cache
|
|
17
|
+
if (cache && isEqual(args, cache[0])) return cache[1];
|
|
18
18
|
const val = selectorFunc(...args);
|
|
19
|
-
cache =
|
|
20
|
-
args,
|
|
21
|
-
val
|
|
22
|
-
};
|
|
19
|
+
cache = [args, val];
|
|
23
20
|
return val;
|
|
24
21
|
},
|
|
25
22
|
subscribe: createSubscriber(items)
|
|
@@ -4,6 +4,13 @@ const createState = ({
|
|
|
4
4
|
let value = initialValue;
|
|
5
5
|
const listeners = new Set();
|
|
6
6
|
const get = () => value;
|
|
7
|
+
const readonlyState = {
|
|
8
|
+
get,
|
|
9
|
+
subscribe: listener => {
|
|
10
|
+
listeners.add(listener);
|
|
11
|
+
return () => listeners.delete(listener);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
7
14
|
let set = newValue => {
|
|
8
15
|
const nextValue = typeof newValue === 'function' ? newValue(value) : newValue;
|
|
9
16
|
if (!Object.is(value, nextValue)) {
|
|
@@ -12,20 +19,14 @@ const createState = ({
|
|
|
12
19
|
listeners.forEach(listener => listener(nextValue, prevValue));
|
|
13
20
|
}
|
|
14
21
|
};
|
|
15
|
-
const subscribe = listener => {
|
|
16
|
-
listeners.add(listener);
|
|
17
|
-
return () => listeners.delete(listener);
|
|
18
|
-
};
|
|
19
22
|
if (middleware) set = middleware({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
subscribe
|
|
23
|
+
...readonlyState,
|
|
24
|
+
set
|
|
23
25
|
}, config);
|
|
24
26
|
return {
|
|
25
27
|
...actionBuilder?.(set, get),
|
|
26
|
-
|
|
27
|
-
set
|
|
28
|
-
subscribe
|
|
28
|
+
...readonlyState,
|
|
29
|
+
set
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
const state = /*#__PURE__*/createState();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactish-state",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1-alpha.1",
|
|
4
4
|
"description": "Simple, decentralized (atomic) state management for React.",
|
|
5
5
|
"author": "Zheng Song",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"use-sync-external-store": "^1.5.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@babel/core": "^7.28.
|
|
86
|
+
"@babel/core": "^7.28.4",
|
|
87
87
|
"@babel/preset-env": "^7.28.3",
|
|
88
88
|
"@babel/preset-react": "^7.27.1",
|
|
89
89
|
"@babel/preset-typescript": "^7.27.1",
|
|
@@ -91,29 +91,29 @@
|
|
|
91
91
|
"@rollup/plugin-babel": "^6.0.4",
|
|
92
92
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
93
93
|
"@rollup/plugin-replace": "^6.0.2",
|
|
94
|
-
"@testing-library/jest-dom": "^6.
|
|
94
|
+
"@testing-library/jest-dom": "^6.8.0",
|
|
95
95
|
"@testing-library/react": "^16.3.0",
|
|
96
96
|
"@types/jest": "^30.0.0",
|
|
97
|
-
"@types/react": "^19.1.
|
|
97
|
+
"@types/react": "^19.1.12",
|
|
98
98
|
"@types/use-sync-external-store": "^1.5.0",
|
|
99
99
|
"babel-plugin-pure-annotations": "^0.1.2",
|
|
100
100
|
"deplift": "^1.0.1",
|
|
101
|
-
"eslint": "^9.
|
|
101
|
+
"eslint": "^9.35.0",
|
|
102
102
|
"eslint-config-prettier": "^10.1.8",
|
|
103
103
|
"eslint-plugin-jest": "^29.0.1",
|
|
104
104
|
"eslint-plugin-react": "^7.37.5",
|
|
105
105
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
106
106
|
"eslint-plugin-react-hooks-addons": "^0.5.0",
|
|
107
107
|
"globals": "^16.3.0",
|
|
108
|
-
"immer": "^10.1.
|
|
109
|
-
"jest": "^30.
|
|
110
|
-
"jest-environment-jsdom": "^30.
|
|
108
|
+
"immer": "^10.1.3",
|
|
109
|
+
"jest": "^30.1.3",
|
|
110
|
+
"jest-environment-jsdom": "^30.1.2",
|
|
111
111
|
"npm-run-all": "^4.1.5",
|
|
112
112
|
"prettier": "^3.6.2",
|
|
113
113
|
"react": "^19.1.1",
|
|
114
114
|
"react-dom": "^19.1.1",
|
|
115
|
-
"rollup": "^4.
|
|
115
|
+
"rollup": "^4.50.1",
|
|
116
116
|
"typescript": "^5.9.2",
|
|
117
|
-
"typescript-eslint": "^8.
|
|
117
|
+
"typescript-eslint": "^8.42.0"
|
|
118
118
|
}
|
|
119
119
|
}
|