@uniflowed/state 0.2.0 → 0.4.0
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/internal/atom.js +6 -1
- package/internal/composed.js +10 -3
- package/package.json +3 -3
package/internal/atom.js
CHANGED
|
@@ -79,8 +79,13 @@ export type AtomSetter = <V, A>(target: AtomRecord<V, A>, arg: A) => void;
|
|
|
79
79
|
* of `AtomRecord<T, empty>`: a writable atom is accepted anywhere a readable
|
|
80
80
|
* one is, and the argument type stays exact at the call site rather than
|
|
81
81
|
* widening to `mixed` the moment an atom is passed somewhere general.
|
|
82
|
+
*
|
|
83
|
+
* `in A` says so to the checker. `A` appears only as the write's argument, so
|
|
84
|
+
* it is contravariant, but Flow compares two applications of an alias by the
|
|
85
|
+
* variance written on its parameters. Without the annotation, `get(value)` on
|
|
86
|
+
* a primitive was "SetAction<T> is incompatible with empty".
|
|
82
87
|
*/
|
|
83
|
-
export type AtomRecord<T, A> = {
|
|
88
|
+
export type AtomRecord<T, in A> = {
|
|
84
89
|
readonly kind: "primitive" | "derived" | "async",
|
|
85
90
|
/** For diagnostics only. Never load-bearing. */
|
|
86
91
|
readonly label: string,
|
package/internal/composed.js
CHANGED
|
@@ -530,7 +530,14 @@ export function createJSONStorage<T>(
|
|
|
530
530
|
return;
|
|
531
531
|
}
|
|
532
532
|
try {
|
|
533
|
-
|
|
533
|
+
const serialized = JSON.stringify(value);
|
|
534
|
+
// `undefined` has no JSON. Nothing stored reads back as the initial
|
|
535
|
+
// value, which is what a stored "undefined" failing to parse did.
|
|
536
|
+
if (serialized === undefined) {
|
|
537
|
+
store.removeItem(key);
|
|
538
|
+
} else {
|
|
539
|
+
store.setItem(key, serialized);
|
|
540
|
+
}
|
|
534
541
|
} catch {
|
|
535
542
|
// Out of quota, or site data blocked. The value is still the atom's;
|
|
536
543
|
// it simply will not outlive the tab.
|
|
@@ -558,7 +565,7 @@ export function createJSONStorage<T>(
|
|
|
558
565
|
if (event.key != null && event.key !== key) {
|
|
559
566
|
return;
|
|
560
567
|
}
|
|
561
|
-
onChange(parse(event.key == null ? null : event.newValue, initial));
|
|
568
|
+
onChange(parse(event.key == null ? null : (event.newValue ?? null), initial));
|
|
562
569
|
};
|
|
563
570
|
host.addEventListener("storage", listener);
|
|
564
571
|
return () => {
|
|
@@ -816,7 +823,7 @@ export function unwrap<T>(
|
|
|
816
823
|
return defineSelector((get) => {
|
|
817
824
|
const settled = get(target);
|
|
818
825
|
return match (settled) {
|
|
819
|
-
{state: "hasData", data: const data
|
|
826
|
+
{state: "hasData", data: const data} => data,
|
|
820
827
|
_ => fallback,
|
|
821
828
|
};
|
|
822
829
|
}, null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniflowed/state",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Atoms and the React binding for @uniflowed/state, part of the Unified Toolchain for Flow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"!*.test.js"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@uniflowed/cell": "0.
|
|
23
|
-
"@uniflowed/react": "0.
|
|
22
|
+
"@uniflowed/cell": "0.4.0",
|
|
23
|
+
"@uniflowed/react": "0.4.0"
|
|
24
24
|
}
|
|
25
25
|
}
|