@plq/use-persisted-state 1.2.0 → 1.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.
Files changed (110) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +168 -43
  3. package/esm/index.d.mts +13 -0
  4. package/esm/index.mjs +10 -0
  5. package/esm/storages/browser-storage.d.mts +1 -0
  6. package/esm/storages/browser-storage.mjs +5 -0
  7. package/esm/storages/chrome-storage.d.mts +1 -0
  8. package/esm/storages/chrome-storage.mjs +5 -0
  9. package/esm/storages/local-storage.d.mts +1 -0
  10. package/esm/storages/local-storage.mjs +3 -0
  11. package/esm/storages/session-storage.d.mts +1 -0
  12. package/esm/storages/session-storage.mjs +3 -0
  13. package/lib/@types/storage.d.ts.map +1 -1
  14. package/lib/create-async-persisted-state.d.ts +2 -2
  15. package/lib/create-async-persisted-state.d.ts.map +1 -1
  16. package/lib/create-async-persisted-state.js +63 -13
  17. package/lib/create-async-persisted-state.js.map +1 -1
  18. package/lib/create-persisted-state.d.ts +2 -2
  19. package/lib/create-persisted-state.d.ts.map +1 -1
  20. package/lib/create-persisted-state.js +32 -14
  21. package/lib/create-persisted-state.js.map +1 -1
  22. package/lib/index.d.ts +6 -5
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +5 -3
  25. package/lib/index.js.map +1 -1
  26. package/lib/storages/browser-storage.d.ts +2 -2
  27. package/lib/storages/browser-storage.d.ts.map +1 -1
  28. package/lib/storages/browser-storage.js +6 -26
  29. package/lib/storages/browser-storage.js.map +1 -1
  30. package/lib/storages/chrome-storage.d.ts +2 -2
  31. package/lib/storages/chrome-storage.d.ts.map +1 -1
  32. package/lib/storages/chrome-storage.js +10 -27
  33. package/lib/storages/chrome-storage.js.map +1 -1
  34. package/lib/storages/local-storage.d.ts +1 -1
  35. package/lib/storages/local-storage.d.ts.map +1 -1
  36. package/lib/storages/local-storage.js +3 -1
  37. package/lib/storages/local-storage.js.map +1 -1
  38. package/lib/storages/session-storage.d.ts +1 -1
  39. package/lib/storages/session-storage.d.ts.map +1 -1
  40. package/lib/storages/session-storage.js +3 -1
  41. package/lib/storages/session-storage.js.map +1 -1
  42. package/lib/utils/change-notifier.d.ts +18 -0
  43. package/lib/utils/change-notifier.d.ts.map +1 -0
  44. package/lib/utils/change-notifier.js +38 -0
  45. package/lib/utils/change-notifier.js.map +1 -0
  46. package/lib/utils/create-web-storage.d.ts +10 -2
  47. package/lib/utils/create-web-storage.d.ts.map +1 -1
  48. package/lib/utils/create-web-storage.js +72 -75
  49. package/lib/utils/create-web-storage.js.map +1 -1
  50. package/lib/utils/extension-storage.d.ts +38 -0
  51. package/lib/utils/extension-storage.d.ts.map +1 -0
  52. package/lib/utils/extension-storage.js +66 -0
  53. package/lib/utils/extension-storage.js.map +1 -0
  54. package/lib/utils/get-new-item.d.ts.map +1 -1
  55. package/lib/utils/get-new-item.js +1 -1
  56. package/lib/utils/get-new-item.js.map +1 -1
  57. package/lib/utils/get-new-value.d.ts +1 -1
  58. package/lib/utils/get-new-value.d.ts.map +1 -1
  59. package/lib/utils/get-new-value.js +1 -1
  60. package/lib/utils/get-new-value.js.map +1 -1
  61. package/lib/utils/get-persisted-value.d.ts +8 -1
  62. package/lib/utils/get-persisted-value.d.ts.map +1 -1
  63. package/lib/utils/get-persisted-value.js +20 -6
  64. package/lib/utils/get-persisted-value.js.map +1 -1
  65. package/lib/utils/is-async-storage.d.ts +7 -0
  66. package/lib/utils/is-async-storage.d.ts.map +1 -1
  67. package/lib/utils/is-async-storage.js +52 -30
  68. package/lib/utils/is-async-storage.js.map +1 -1
  69. package/lib/utils/storage-event-router.d.ts +17 -0
  70. package/lib/utils/storage-event-router.d.ts.map +1 -0
  71. package/lib/utils/storage-event-router.js +54 -0
  72. package/lib/utils/storage-event-router.js.map +1 -0
  73. package/lib/utils/use-storage-handler.d.ts +3 -3
  74. package/lib/utils/use-storage-handler.d.ts.map +1 -1
  75. package/lib/utils/use-storage-handler.js +80 -26
  76. package/lib/utils/use-storage-handler.js.map +1 -1
  77. package/package.json +105 -44
  78. package/src/@types/storage.ts +13 -13
  79. package/src/create-async-persisted-state.ts +81 -18
  80. package/src/create-persisted-state.ts +48 -22
  81. package/src/index.ts +12 -7
  82. package/src/storages/browser-storage.ts +8 -36
  83. package/src/storages/chrome-storage.ts +24 -46
  84. package/src/storages/local-storage.ts +3 -1
  85. package/src/storages/session-storage.ts +3 -1
  86. package/src/utils/change-notifier.ts +43 -0
  87. package/src/utils/create-web-storage.ts +74 -77
  88. package/src/utils/extension-storage.ts +79 -0
  89. package/src/utils/get-new-item.ts +1 -1
  90. package/src/utils/get-new-value.ts +1 -1
  91. package/src/utils/get-persisted-value.ts +23 -8
  92. package/src/utils/is-async-storage.ts +72 -37
  93. package/src/utils/storage-event-router.ts +67 -0
  94. package/src/utils/use-storage-handler.ts +112 -36
  95. package/storages/browser-storage.d.ts +1 -0
  96. package/storages/browser-storage.js +11 -0
  97. package/storages/chrome-storage.d.ts +1 -0
  98. package/storages/chrome-storage.js +11 -0
  99. package/storages/local-storage.d.ts +1 -0
  100. package/storages/local-storage.js +9 -0
  101. package/storages/session-storage.d.ts +1 -0
  102. package/storages/session-storage.js +9 -0
  103. package/lib/utils/is-function.d.ts +0 -2
  104. package/lib/utils/is-function.d.ts.map +0 -1
  105. package/lib/utils/is-function.js +0 -9
  106. package/lib/utils/is-function.js.map +0 -1
  107. package/lib/utils/is-promise.d.ts +0 -2
  108. package/lib/utils/is-promise.d.ts.map +0 -1
  109. package/lib/utils/is-promise.js +0 -10
  110. package/lib/utils/is-promise.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"get-new-item.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAU,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAelF"}
1
+ {"version":3,"file":"get-new-item.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,MAAM,CAenF"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
3
4
  function default_1(key, persistedItem, newValue) {
4
5
  let persist;
5
6
  try {
@@ -13,5 +14,4 @@ function default_1(key, persistedItem, newValue) {
13
14
  [key]: newValue,
14
15
  }));
15
16
  }
16
- exports.default = default_1;
17
17
  //# sourceMappingURL=get-new-item.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-new-item.js","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":";;AAAA,mBAA2B,GAAW,EAAE,aAAqB,EAAE,QAAW;IACxE,IAAI,OAAiC,CAAA;IAErC,IAAI;QACF,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;KACzD;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,OAAO,GAAG,EAAE,CAAA;KACb;IAED,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACrB,CAAC,GAAG,CAAC,EAAE,QAAQ;KAChB,CAAC,CACH,CAAA;AACH,CAAC;AAfD,4BAeC"}
1
+ {"version":3,"file":"get-new-item.js","sourceRoot":"","sources":["../../src/utils/get-new-item.ts"],"names":[],"mappings":";;AAAA,4BAeC;AAfD,mBAA4B,GAAW,EAAE,aAAqB,EAAE,QAAW;IACzE,IAAI,OAAiC,CAAA;IAErC,IAAI,CAAC;QACH,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,OAAO,GAAG,EAAE,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACrB,CAAC,GAAG,CAAC,EAAE,QAAQ;KAChB,CAAC,CACH,CAAA;AACH,CAAC"}
@@ -1,3 +1,3 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  export default function <T>(newState: React.SetStateAction<T>, state: T): T;
3
3
  //# sourceMappingURL=get-new-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-new-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,CAAC,OAAO,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAU1E"}
1
+ {"version":3,"file":"get-new-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,CAAC,OAAO,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAU1E"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
3
4
  const is_1 = require("@plq/is");
4
5
  function default_1(newState, state) {
5
6
  let newValue;
@@ -11,5 +12,4 @@ function default_1(newState, state) {
11
12
  }
12
13
  return newValue;
13
14
  }
14
- exports.default = default_1;
15
15
  //# sourceMappingURL=get-new-value.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-new-value.js","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":";;AACA,gCAAoC;AAEpC,mBAA4B,QAAiC,EAAE,KAAQ;IACrE,IAAI,QAAW,CAAA;IAEf,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;QACxB,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;KAC3B;SAAM;QACL,QAAQ,GAAG,QAAQ,CAAA;KACpB;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAVD,4BAUC"}
1
+ {"version":3,"file":"get-new-value.js","sourceRoot":"","sources":["../../src/utils/get-new-value.ts"],"names":[],"mappings":";;AAGA,4BAUC;AAZD,gCAAoC;AAEpC,mBAA4B,QAAiC,EAAE,KAAQ;IACrE,IAAI,QAAW,CAAA;IAEf,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,QAAQ,CAAA;IACrB,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -1,2 +1,9 @@
1
- export default function <T>(key: string, initialValue: T | (() => T), persist?: string): T;
1
+ /**
2
+ * Resolves the value a hook starts from: the persisted entry for `key` when the stored payload
3
+ * carries one, the initial value otherwise.
4
+ *
5
+ * Presence is decided by the key rather than by the value, so a persisted `null` comes back as
6
+ * the value the user set instead of being mistaken for an absence and replaced.
7
+ */
8
+ export default function getPersistedValue<T>(key: string, initialValue: T | (() => T), persist?: string): T;
2
9
  //# sourceMappingURL=get-persisted-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-persisted-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-persisted-value.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,WAAU,CAAC,EAAE,GAAG,EAAC,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAgBvF"}
1
+ {"version":3,"file":"get-persisted-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-persisted-value.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAwB1G"}
@@ -1,19 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getPersistedValue;
3
4
  const is_1 = require("@plq/is");
4
- function default_1(key, initialValue, persist) {
5
+ /**
6
+ * Resolves the value a hook starts from: the persisted entry for `key` when the stored payload
7
+ * carries one, the initial value otherwise.
8
+ *
9
+ * Presence is decided by the key rather than by the value, so a persisted `null` comes back as
10
+ * the value the user set instead of being mistaken for an absence and replaced.
11
+ */
12
+ function getPersistedValue(key, initialValue, persist) {
5
13
  let initialPersist;
6
14
  try {
7
15
  initialPersist = persist ? JSON.parse(persist) : {};
8
16
  }
9
- catch (ignore) {
17
+ catch (err) {
18
+ // A shared backend can hold a foreign or truncated entry, so a parse failure is expected here
19
+ // and must not stop the component mounting. It is reported rather than swallowed because the
20
+ // fallback discards whatever was persisted, and because the change path logs the same failure.
21
+ console.error("use-persisted-state: Can't parse value from storage", err);
10
22
  initialPersist = {};
11
- } // eslint-disable-line no-empty
23
+ }
12
24
  let initialOrPersistedValue = (0, is_1.isFunction)(initialValue) ? initialValue() : initialValue;
13
- if (initialPersist && key in initialPersist) {
14
- initialOrPersistedValue = initialPersist[key] || initialOrPersistedValue;
25
+ // `JSON.parse` yields any JSON value, so a foreign entry can be a primitive,
26
+ // and `in` throws on one. This runs in the `useState` initializer, where a
27
+ // throw stops the component mounting instead of falling back.
28
+ if ((0, is_1.isObject)(initialPersist) && key in initialPersist) {
29
+ initialOrPersistedValue = initialPersist[key];
15
30
  }
16
31
  return initialOrPersistedValue;
17
32
  }
18
- exports.default = default_1;
19
33
  //# sourceMappingURL=get-persisted-value.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-persisted-value.js","sourceRoot":"","sources":["../../src/utils/get-persisted-value.ts"],"names":[],"mappings":";;AAAA,gCAAoC;AAEpC,mBAA2B,GAAU,EAAE,YAA2B,EAAE,OAAgB;IAClF,IAAI,cAAwC,CAAA;IAE5C,IAAI;QACF,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;KACpD;IAAC,OAAO,MAAM,EAAE;QACf,cAAc,GAAG,EAAE,CAAA;KACpB,CAAC,+BAA+B;IAEjC,IAAI,uBAAuB,GAAG,IAAA,eAAU,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAE,CAAC,CAAC,YAAY,CAAA;IAEvF,IAAI,cAAc,IAAI,GAAG,IAAI,cAAc,EAAE;QAC3C,uBAAuB,GAAI,cAAc,CAAC,GAAG,CAAO,IAAI,uBAAuB,CAAA;KAChF;IAED,OAAO,uBAAuB,CAAA;AAChC,CAAC;AAhBD,4BAgBC"}
1
+ {"version":3,"file":"get-persisted-value.js","sourceRoot":"","sources":["../../src/utils/get-persisted-value.ts"],"names":[],"mappings":";;AASA,oCAwBC;AAjCD,gCAA8C;AAE9C;;;;;;GAMG;AACH,SAAwB,iBAAiB,CAAI,GAAW,EAAE,YAA2B,EAAE,OAAgB;IACrG,IAAI,cAAuB,CAAA;IAE3B,IAAI,CAAC;QACH,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACrD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,8FAA8F;QAC9F,6FAA6F;QAC7F,+FAA+F;QAC/F,OAAO,CAAC,KAAK,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAA;QAEzE,cAAc,GAAG,EAAE,CAAA;IACrB,CAAC;IAED,IAAI,uBAAuB,GAAG,IAAA,eAAU,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAA;IAEtF,6EAA6E;IAC7E,2EAA2E;IAC3E,8DAA8D;IAC9D,IAAI,IAAA,aAAQ,EAAC,cAAc,CAAC,IAAI,GAAG,IAAI,cAAc,EAAE,CAAC;QACtD,uBAAuB,GAAG,cAAc,CAAC,GAAG,CAAM,CAAA;IACpD,CAAC;IAED,OAAO,uBAAuB,CAAA;AAChC,CAAC"}
@@ -1,3 +1,10 @@
1
1
  import type { AsyncStorage } from '../@types/storage';
2
+ /**
3
+ * Narrows a storage to {@link AsyncStorage}, deciding which hook the entry point builds.
4
+ *
5
+ * Inspection never writes: `set` and `remove` are only checked for shape, never invoked, so
6
+ * `get` alone decides. A candidate pairing an async `get` with a sync `set` satisfies neither
7
+ * storage interface, which is why proving the other two members is not worth a write.
8
+ */
2
9
  export default function isAsyncStorage(storage: unknown): storage is AsyncStorage;
3
10
  //# sourceMappingURL=is-async-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-async-storage.d.ts","sourceRoot":"","sources":["../../src/utils/is-async-storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAA;AAEnD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,YAAY,CAoChF"}
1
+ {"version":3,"file":"is-async-storage.d.ts","sourceRoot":"","sources":["../../src/utils/is-async-storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAcrD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,YAAY,CAoDhF"}
@@ -1,38 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = isAsyncStorage;
3
4
  const is_1 = require("@plq/is");
5
+ // `AsyncStorage` is three methods, so every member has to be callable: a promise standing in for
6
+ // one satisfies nothing the hook then does with it. `@plq/is` classifies async functions as their
7
+ // own type, so `isFunction` rejects them and both checks are needed to admit a callable member.
8
+ const isCallableMember = (member) => (0, is_1.isFunction)(member) || (0, is_1.isAsyncFunction)(member);
9
+ /**
10
+ * Narrows a storage to {@link AsyncStorage}, deciding which hook the entry point builds.
11
+ *
12
+ * Inspection never writes: `set` and `remove` are only checked for shape, never invoked, so
13
+ * `get` alone decides. A candidate pairing an async `get` with a sync `set` satisfies neither
14
+ * storage interface, which is why proving the other two members is not worth a write.
15
+ */
4
16
  function isAsyncStorage(storage) {
5
- const hasGet = Boolean(storage) && typeof storage?.get !== 'undefined';
6
- const hasSet = Boolean(storage) && typeof storage?.set !== 'undefined';
7
- const hasRemove = Boolean(storage) && typeof storage?.remove !== 'undefined';
8
- if (!hasGet || !hasSet || !hasRemove) {
17
+ const candidate = storage;
18
+ if (!candidate) {
19
+ return false;
20
+ }
21
+ const { get, set, remove } = candidate;
22
+ if (!isCallableMember(set) || !isCallableMember(remove)) {
23
+ return false;
24
+ }
25
+ // An `async` declaration is the one form of asyncness visible without a call.
26
+ if ((0, is_1.isAsyncFunction)(get)) {
27
+ return true;
28
+ }
29
+ if (!(0, is_1.isFunction)(get)) {
9
30
  return false;
10
31
  }
11
- const hasGetPromise = (0, is_1.isPromise)(storage.get)
12
- || (0, is_1.isFunction)(storage.get) && (0, is_1.isPromise)(storage.get(''))
13
- || (0, is_1.isAsyncFunction)(storage.get);
14
- const hasSetPromise = (0, is_1.isPromise)(storage.set)
15
- || (0, is_1.isFunction)(storage.set) && (0, is_1.isPromise)(storage.set({}))
16
- || (0, is_1.isAsyncFunction)(storage.set);
17
- const hasRemovePromise = (0, is_1.isPromise)(storage.remove)
18
- || (0, is_1.isFunction)(storage.remove) && (0, is_1.isPromise)(storage.remove(''))
19
- || (0, is_1.isAsyncFunction)(storage.remove);
20
- console.log('isAsyncStorage', {
21
- storage,
22
- hasGet,
23
- hasSet,
24
- hasRemove,
25
- hasGetPromise,
26
- hasSetPromise,
27
- hasRemovePromise,
28
- });
29
- return Boolean(storage)
30
- && hasGet
31
- && hasSet
32
- && hasRemove
33
- && hasGetPromise
34
- && hasSetPromise
35
- && hasRemovePromise;
32
+ // `AsyncStorage` admits a plain function returning a promise, and nothing short of a call tells
33
+ // that apart from a sync get. Any adapter written that way can only be recognised here, and a
34
+ // third-party one is free to be written that way, so this line stays necessary however the
35
+ // shipped adapters happen to declare themselves. A read is the one probe that leaves the
36
+ // inspected storage as it found it.
37
+ let probe;
38
+ try {
39
+ // Called as a method of the storage it belongs to: an adapter written as an
40
+ // object of methods reads its own state through `this`, and probing the
41
+ // extracted function would throw on a storage that is perfectly valid.
42
+ probe = get.call(candidate, '');
43
+ }
44
+ catch {
45
+ // Not swallowed, deferred: consumers build the factory at module scope, where
46
+ // a throw takes the import down instead of reaching a component. A storage
47
+ // whose read fails is not provably async, and the sync path raises the same
48
+ // failure at the first read, where it can be handled.
49
+ return false;
50
+ }
51
+ if (!(0, is_1.isPromise)(probe)) {
52
+ return false;
53
+ }
54
+ // Only the probe's shape answers the question, so its outcome is discarded by construction.
55
+ // The rejection still has to be claimed: unclaimed, it terminates the process on Node 15+,
56
+ // letting a storage that merely fails a read take the consuming application down with it.
57
+ probe.then(undefined, () => undefined);
58
+ return true;
36
59
  }
37
- exports.default = isAsyncStorage;
38
60
  //# sourceMappingURL=is-async-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-async-storage.js","sourceRoot":"","sources":["../../src/utils/is-async-storage.ts"],"names":[],"mappings":";;AAAA,gCAA8D;AAG9D,SAAwB,cAAc,CAAC,OAAgB;IAC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ACjC,CAAC;IAAC,MAAM,CAAC;QACP,8EAA8E;QAC9E,2EAA2E;QAC3E,4EAA4E;QAC5E,sDAAsD;QACtD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,CAAC,IAAA,cAAS,EAAC,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,4FAA4F;IAC5F,2FAA2F;IAC3F,0FAA0F;IAC1F,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAEtC,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { StorageChange } from '../@types/storage';
2
+ /** An adapter waiting for DOM storage events about the area it wraps. */
3
+ export interface StorageEventRoute {
4
+ storage: globalThis.Storage;
5
+ fire(changes: {
6
+ [key: string]: StorageChange;
7
+ }): void;
8
+ }
9
+ /**
10
+ * Starts routing DOM storage events to `route`. Every adapter shares one
11
+ * subscription on the global object, so creating adapters nobody listens to
12
+ * costs nothing.
13
+ */
14
+ export declare function addRoute(route: StorageEventRoute): void;
15
+ /** Stops routing to `route`, releasing the shared subscription with the last one. */
16
+ export declare function removeRoute(route: StorageEventRoute): void;
17
+ //# sourceMappingURL=storage-event-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-event-router.d.ts","sourceRoot":"","sources":["../../src/utils/storage-event-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAA;IAC3B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,GAAG,IAAI,CAAA;CACtD;AAoCD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAQvD;AAED,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAQ1D"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRoute = addRoute;
4
+ exports.removeRoute = removeRoute;
5
+ const routes = new Set();
6
+ let subscription = null;
7
+ function routeStorageEvent(event) {
8
+ if (!event.key)
9
+ return;
10
+ const changes = {
11
+ [event.key]: {
12
+ newValue: event.newValue,
13
+ oldValue: event.oldValue,
14
+ },
15
+ };
16
+ for (const route of routes) {
17
+ // A browser always names the area it changed, so real cross-tab events
18
+ // reach only the adapter of that area. An event a consumer synthesized —
19
+ // the sole way to test cross-tab sync under jsdom, and a common way to
20
+ // notify the writing tab in production — often cannot name one: the
21
+ // StorageEvent constructor rejects a mocked storage there. Those still go
22
+ // everywhere, exactly as they did before areas were told apart.
23
+ if (event.storageArea == null || event.storageArea === route.storage) {
24
+ route.fire(changes);
25
+ }
26
+ }
27
+ }
28
+ // A runtime can provide storage without the DOM event API, and can provide half
29
+ // of that API: subscribing where nothing can unsubscribe strands a listener and
30
+ // makes releasing it throw, so both halves are required before taking one.
31
+ function canSubscribe() {
32
+ return typeof globalThis.addEventListener === 'function' && typeof globalThis.removeEventListener === 'function';
33
+ }
34
+ /**
35
+ * Starts routing DOM storage events to `route`. Every adapter shares one
36
+ * subscription on the global object, so creating adapters nobody listens to
37
+ * costs nothing.
38
+ */
39
+ function addRoute(route) {
40
+ routes.add(route);
41
+ if (!subscription && canSubscribe()) {
42
+ subscription = routeStorageEvent;
43
+ globalThis.addEventListener('storage', subscription);
44
+ }
45
+ }
46
+ /** Stops routing to `route`, releasing the shared subscription with the last one. */
47
+ function removeRoute(route) {
48
+ routes.delete(route);
49
+ if (routes.size === 0 && subscription) {
50
+ globalThis.removeEventListener('storage', subscription);
51
+ subscription = null;
52
+ }
53
+ }
54
+ //# sourceMappingURL=storage-event-router.js.map
@@ -0,0 +1 @@
1
+ {"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AC,KAAwB;IAClD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAEpB,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,YAAY,EAAE,CAAC;QACtC,UAAU,CAAC,mBAAmB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAEvD,YAAY,GAAG,IAAI,CAAA;IACrB,CAAC;AACH,CAAC"}
@@ -1,4 +1,4 @@
1
- import React from 'react';
2
- import { AsyncStorage, Storage } from '../@types/storage';
3
- export default function <T>(key: string, storageKey: string, setState: React.Dispatch<React.SetStateAction<T>>, storage: AsyncStorage | Storage, initialValue: T | (() => T)): void;
1
+ import type React from 'react';
2
+ import type { AsyncStorage, Storage } from '../@types/storage';
3
+ export default function useStorageHandler<T>(key: string, storageKey: string, applyValue: (value: T) => void, storage: AsyncStorage | Storage, initialValue: T | (() => T), pendingOwnWrite: React.RefObject<string | null>): void;
4
4
  //# sourceMappingURL=use-storage-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-storage-handler.d.ts","sourceRoot":"","sources":["../../src/utils/use-storage-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAiB,MAAM,mBAAmB,CAAA;AAiDxE,MAAM,CAAC,OAAO,WAAU,CAAC,EACvB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACjD,OAAO,EAAE,YAAY,GAAG,OAAO,EAC/B,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAC1B,IAAI,CAYN"}
1
+ {"version":3,"file":"use-storage-handler.d.ts","sourceRoot":"","sources":["../../src/utils/use-storage-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAiB,MAAM,mBAAmB,CAAA;AAiH7E,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,CAAC,EACzC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC9B,OAAO,EAAE,YAAY,GAAG,OAAO,EAC/B,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAC3B,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,GAC9C,IAAI,CAsBN"}
@@ -1,48 +1,102 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = useStorageHandler;
3
4
  const react_1 = require("react");
4
5
  const is_1 = require("@plq/is");
5
- function getValue(key, value) {
6
- let newState = null;
6
+ function readStoredValue(key, entry) {
7
+ let parsed;
7
8
  try {
8
- newState = JSON.parse(value);
9
+ parsed = JSON.parse(entry);
9
10
  }
10
11
  catch (err) {
11
- console.error('use-persisted-state: Can\'t parse value from storage', err);
12
+ console.error("use-persisted-state: Can't parse value from storage", err);
13
+ return { status: 'unavailable' };
12
14
  }
13
- return newState && key in newState ? newState[key] : null;
15
+ // A foreign entry can be any JSON value, and `in` throws on a primitive. This
16
+ // runs inside the adapter's notify loop, where a throw also cuts off every
17
+ // listener queued behind this one.
18
+ if (!(0, is_1.isObject)(parsed) || !(key in parsed))
19
+ return { status: 'unavailable' };
20
+ return { status: 'stored', value: parsed[key] };
14
21
  }
15
- function useStorageHandler(itemKey, storageKey, setState, initialValue) {
22
+ // Restores the initial value when the whole entry is removed from the storage.
23
+ function applyRemoval(change, itemKey, applyValue, latestInitialValue) {
24
+ if (change.oldValue === null || change.oldValue === undefined)
25
+ return;
26
+ const oldValue = readStoredValue(itemKey, change.oldValue);
27
+ const declaredInitialValue = latestInitialValue.current;
28
+ // Compared against the resolved value: a factory is never equal to what it
29
+ // produces, so comparing the declaration re-applies the initial value on every
30
+ // removal.
31
+ const initialValue = (0, is_1.isFunction)(declaredInitialValue) ? declaredInitialValue() : declaredInitialValue;
32
+ // An entry with no readable value for the key cannot be shown to have held the
33
+ // initial value, so the fallback is applied rather than skipped. The entry is
34
+ // gone either way, and stale state left in place is worse than a redundant
35
+ // restore.
36
+ if (oldValue.status === 'stored' && oldValue.value === initialValue)
37
+ return;
38
+ applyValue(initialValue);
39
+ }
40
+ /**
41
+ * Reports whether this change is the write the hook itself just made, forgetting
42
+ * the record when it is. A backend reports a write to every listener, the one
43
+ * that made it included, and applying that echo is the storage-to-state re-sync
44
+ * this hook was rebuilt without, arriving by another road: it decodes the entry
45
+ * again and hands the caller an equal value with a new identity, plus a render
46
+ * for a value it already holds.
47
+ *
48
+ * The price, accepted knowingly: for a value JSON cannot carry, the writer keeps
49
+ * what it set - NaN - while every other component on the key decodes the null
50
+ * that reached storage, so the two disagree until one of them remounts. Applying
51
+ * the echo would settle that disagreement and bring back both the second
52
+ * storage-to-state path and the render per write, so it is not the repair it
53
+ * looks like.
54
+ *
55
+ * Forgetting on the first match keeps a later identical entry a change. Another
56
+ * hook writing the same bytes is suppressed along with it, and nothing is lost:
57
+ * it would have replaced a value with an equal one.
58
+ */
59
+ function consumeOwnWriteEcho(change, pendingOwnWrite) {
60
+ if (pendingOwnWrite.current === null || change.newValue !== pendingOwnWrite.current)
61
+ return false;
62
+ pendingOwnWrite.current = null;
63
+ return true;
64
+ }
65
+ // Builds the change handler. Not a hook, despite living next to one.
66
+ function createStorageHandler(itemKey, storageKey, applyValue, latestInitialValue, pendingOwnWrite) {
16
67
  return (changes) => {
17
- Object.entries(changes).forEach(([key, change]) => {
18
- if (key === storageKey
19
- && (change.newValue === null || change.newValue === undefined)
20
- && change.oldValue !== null
21
- && change.oldValue !== undefined) {
22
- const oldValue = getValue(itemKey, change.oldValue);
23
- if (oldValue !== initialValue)
24
- setState((0, is_1.isFunction)(initialValue) ? initialValue() : initialValue);
25
- }
26
- if (key === storageKey
27
- && change.newValue !== null
28
- && change.newValue !== undefined) {
29
- const newValue = getValue(itemKey, change.newValue);
30
- if (newValue !== null)
31
- setState(newValue);
68
+ for (const [key, change] of Object.entries(changes)) {
69
+ if (key !== storageKey)
70
+ continue;
71
+ if (consumeOwnWriteEcho(change, pendingOwnWrite))
72
+ continue;
73
+ if (change.newValue === null || change.newValue === undefined) {
74
+ applyRemoval(change, itemKey, applyValue, latestInitialValue);
75
+ continue;
32
76
  }
33
- });
77
+ const newValue = readStoredValue(itemKey, change.newValue);
78
+ if (newValue.status === 'stored')
79
+ applyValue(newValue.value);
80
+ }
34
81
  };
35
82
  }
36
- function default_1(key, storageKey, setState, storage, initialValue) {
83
+ function useStorageHandler(key, storageKey, applyValue, storage, initialValue, pendingOwnWrite) {
84
+ // A removal restores the initial value the hook holds now, the same one the
85
+ // key-change path reads, so a caller whose default travels with its data gets
86
+ // that record's default back rather than the mounted one. Tracked through a ref
87
+ // rather than a dependency because an inline object or factory has a new
88
+ // identity every render, which would tear the subscription down and rebuild it;
89
+ // written during render, as the key the hook is rendering for is.
90
+ const latestInitialValue = (0, react_1.useRef)(initialValue);
91
+ latestInitialValue.current = initialValue;
37
92
  (0, react_1.useEffect)(() => {
38
- const handleStorage = useStorageHandler(key, storageKey, setState, initialValue);
93
+ const handleStorage = createStorageHandler(key, storageKey, applyValue, latestInitialValue, pendingOwnWrite);
39
94
  storage.onChanged.addListener(handleStorage);
40
95
  return () => {
41
96
  if (storage.onChanged.hasListener(handleStorage)) {
42
97
  storage.onChanged.removeListener(handleStorage);
43
98
  }
44
99
  };
45
- }, [initialValue, key, storage.onChanged, storageKey, setState]);
100
+ }, [key, storage.onChanged, storageKey, applyValue, pendingOwnWrite]);
46
101
  }
47
- exports.default = default_1;
48
102
  //# sourceMappingURL=use-storage-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-storage-handler.js","sourceRoot":"","sources":["../../src/utils/use-storage-handler.ts"],"names":[],"mappings":";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