zustand-querystring 0.0.12 → 0.0.13
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/README.md +1 -1
- package/lib/middleware.js +18 -14
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# zustand-querystring
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A Zustand middleware that syncs the store with the querystring.
|
|
4
4
|
|
|
5
5
|
Try on [StackBlitz](https://stackblitz.com/github/nitedani/zustand-querystring/tree/main/examples/react) (You need to click "Open in New Tab")
|
|
6
6
|
|
package/lib/middleware.js
CHANGED
|
@@ -20,22 +20,26 @@ const compact = (newState, initialState) => {
|
|
|
20
20
|
});
|
|
21
21
|
return output;
|
|
22
22
|
};
|
|
23
|
-
const translateSelectionToState = (selection, state) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return acc;
|
|
23
|
+
const translateSelectionToState = (selection, state) => {
|
|
24
|
+
if (typeof state !== 'object' || !state) {
|
|
25
|
+
return {};
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
acc[key] = state[key];
|
|
27
|
+
return Object.keys(selection).reduce((acc, key) => {
|
|
28
|
+
if (!(key in state)) {
|
|
29
|
+
return acc;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
31
|
+
const value = selection[key];
|
|
32
|
+
if (typeof value === 'boolean') {
|
|
33
|
+
if (value) {
|
|
34
|
+
acc[key] = state[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
acc[key] = translateSelectionToState(value, state[key]);
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
41
|
+
}, {});
|
|
42
|
+
};
|
|
39
43
|
const escapeStringRegexp = string => {
|
|
40
44
|
if (typeof string !== 'string') {
|
|
41
45
|
throw new TypeError('Expected a string');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zustand-querystring",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"zustand": "^4.3.2"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
+
"dev": "tsc -b --watch",
|
|
41
42
|
"build": "rimraf lib && tsc -b"
|
|
42
43
|
}
|
|
43
44
|
}
|