@plq/use-persisted-state 1.4.1 → 1.4.3

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 (64) hide show
  1. package/README.md +3 -3
  2. package/lib/create-async-persisted-state.d.ts.map +1 -1
  3. package/lib/create-async-persisted-state.js +14 -89
  4. package/lib/create-async-persisted-state.js.map +1 -1
  5. package/lib/create-persisted-state.d.ts.map +1 -1
  6. package/lib/create-persisted-state.js +6 -53
  7. package/lib/create-persisted-state.js.map +1 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/storages/chrome-storage.d.ts.map +1 -1
  10. package/lib/storages/chrome-storage.js +6 -15
  11. package/lib/storages/chrome-storage.js.map +1 -1
  12. package/lib/storages/local-storage.d.ts.map +1 -1
  13. package/lib/storages/local-storage.js +1 -2
  14. package/lib/storages/local-storage.js.map +1 -1
  15. package/lib/storages/session-storage.d.ts.map +1 -1
  16. package/lib/storages/session-storage.js +1 -2
  17. package/lib/storages/session-storage.js.map +1 -1
  18. package/lib/utils/change-notifier.d.ts +1 -8
  19. package/lib/utils/change-notifier.d.ts.map +1 -1
  20. package/lib/utils/change-notifier.js +1 -10
  21. package/lib/utils/change-notifier.js.map +1 -1
  22. package/lib/utils/create-web-storage.d.ts +1 -8
  23. package/lib/utils/create-web-storage.d.ts.map +1 -1
  24. package/lib/utils/create-web-storage.js +5 -17
  25. package/lib/utils/create-web-storage.js.map +1 -1
  26. package/lib/utils/extension-storage.d.ts +2 -12
  27. package/lib/utils/extension-storage.d.ts.map +1 -1
  28. package/lib/utils/extension-storage.js +3 -14
  29. package/lib/utils/extension-storage.js.map +1 -1
  30. package/lib/utils/get-new-item.d.ts +1 -12
  31. package/lib/utils/get-new-item.d.ts.map +1 -1
  32. package/lib/utils/get-new-item.js +2 -16
  33. package/lib/utils/get-new-item.js.map +1 -1
  34. package/lib/utils/get-persisted-value.d.ts +1 -7
  35. package/lib/utils/get-persisted-value.d.ts.map +1 -1
  36. package/lib/utils/get-persisted-value.js +3 -13
  37. package/lib/utils/get-persisted-value.js.map +1 -1
  38. package/lib/utils/is-async-storage.d.ts +1 -7
  39. package/lib/utils/is-async-storage.d.ts.map +1 -1
  40. package/lib/utils/is-async-storage.js +6 -25
  41. package/lib/utils/is-async-storage.js.map +1 -1
  42. package/lib/utils/storage-event-router.d.ts +1 -5
  43. package/lib/utils/storage-event-router.d.ts.map +1 -1
  44. package/lib/utils/storage-event-router.js +3 -14
  45. package/lib/utils/storage-event-router.js.map +1 -1
  46. package/lib/utils/use-storage-handler.d.ts +1 -13
  47. package/lib/utils/use-storage-handler.d.ts.map +1 -1
  48. package/lib/utils/use-storage-handler.js +8 -78
  49. package/lib/utils/use-storage-handler.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/create-async-persisted-state.ts +14 -58
  52. package/src/create-persisted-state.ts +6 -22
  53. package/src/index.ts +1 -4
  54. package/src/storages/chrome-storage.ts +6 -18
  55. package/src/storages/local-storage.ts +1 -2
  56. package/src/storages/session-storage.ts +1 -2
  57. package/src/utils/change-notifier.ts +1 -10
  58. package/src/utils/create-web-storage.ts +5 -17
  59. package/src/utils/extension-storage.ts +3 -14
  60. package/src/utils/get-new-item.ts +2 -16
  61. package/src/utils/get-persisted-value.ts +3 -13
  62. package/src/utils/is-async-storage.ts +6 -26
  63. package/src/utils/storage-event-router.ts +3 -14
  64. package/src/utils/use-storage-handler.ts +7 -94
package/README.md CHANGED
@@ -249,9 +249,9 @@ tells a `null` you stored apart from a `null` that JSON produced.
249
249
  keeps `undefined` in memory, as `useState` would, and other components already mounted on that key
250
250
  see no change and keep the value they hold. After a remount or a reload the key is absent, so the
251
251
  initial value comes back.
252
- - **`NaN`, `Infinity`, `-Infinity`** — these are written as `null`. The component that set the value
253
- keeps it until it remounts; every other component on that key reads back `null`, as does any
254
- reader after a reload.
252
+ - **`NaN`, `Infinity`, `-Infinity`** — these are written as `null`. A storage change reported by the
253
+ backend applies that `null` to every listening component, including the writer. Any reader after
254
+ a reload also reads back `null`.
255
255
 
256
256
  ## Contributing
257
257
 
@@ -1 +1 @@
1
- {"version":3,"file":"create-async-persisted-state.d.ts","sourceRoot":"","sources":["../src/create-async-persisted-state.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AAEtE,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,CAAC,SAAS,YAAY,EACtE,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,CAAC,GACT,CAAC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CA+IvC"}
1
+ {"version":3,"file":"create-async-persisted-state.d.ts","sourceRoot":"","sources":["../src/create-async-persisted-state.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AAEtE,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,CAAC,SAAS,YAAY,EACtE,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,CAAC,GACT,CAAC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAmGvC"}
@@ -1,67 +1,25 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.default = createAsyncPersistedState;
40
7
  const react_1 = require("react");
41
- const use_storage_handler_1 = __importStar(require("./utils/use-storage-handler"));
8
+ const use_storage_handler_1 = __importDefault(require("./utils/use-storage-handler"));
42
9
  const get_new_value_1 = __importDefault(require("./utils/get-new-value"));
43
10
  const get_new_item_1 = __importDefault(require("./utils/get-new-item"));
44
11
  const get_persisted_value_1 = __importDefault(require("./utils/get-persisted-value"));
45
12
  function createAsyncPersistedState(storageKey, storage) {
46
13
  const safeStorageKey = `persisted_state_hook:${storageKey}`;
47
- // Every hook this factory makes lives in one entry, and storing a value means
48
- // reading that entry, merging one key into it and writing all of it back, with
49
- // a suspension point on either side of the merge. Left to overlap, a second
50
- // writer merges into a snapshot taken before the first one landed and stores
51
- // it: the first writer's key is gone from storage while its value is still on
52
- // screen, and nothing reports the disagreement. It is the entry, not the hook,
53
- // that has to be taken one at a time, so the chain belongs to the factory.
14
+ // Storing is read-merge-write on one shared entry, so overlapping writers would drop each other's keys.
54
15
  let entryWrites = Promise.resolve();
55
16
  const clear = () => {
56
- // Removing the entry changes it as much as storing does, so it takes its turn
57
- // in the same chain. Outside it, a write already queued lands after the
58
- // removal and brings back what was cleared - and "clear this data" is the one
59
- // request that cannot be allowed to half happen.
17
+ // In the same chain as writes, or a queued write lands after the removal and restores what was cleared.
60
18
  const removal = entryWrites.then(() => storage.remove(safeStorageKey));
61
19
  entryWrites = removal.catch(() => undefined);
62
20
  return removal;
63
21
  };
64
- const commitEntry = (key, newValue, pendingOwnWrites) => {
22
+ const commitEntry = (key, newValue) => {
65
23
  const write = entryWrites.then(async () => {
66
24
  const persistedItem = await storage.get(safeStorageKey);
67
25
  let newItem;
@@ -69,65 +27,37 @@ function createAsyncPersistedState(storageKey, storage) {
69
27
  newItem = (0, get_new_item_1.default)(key, persistedItem[safeStorageKey], newValue);
70
28
  }
71
29
  catch {
72
- // Refused, and reported where it was refused. A write replaces the whole
73
- // entry, so an entry that cannot be read is one no write can be built on
74
- // without dropping every other hook's key; skipping leaves the bytes for
75
- // a repair to reach. The caller keeps what it set, unpersisted.
30
+ // A write replaces the whole entry, so an unreadable one is skipped rather than rebuilt without other keys.
76
31
  return;
77
32
  }
78
- // Recorded before the write, because the backend may report it before the
79
- // promise settles.
80
- (0, use_storage_handler_1.recordOwnWrite)(pendingOwnWrites, newItem);
81
33
  await storage.set({ [safeStorageKey]: newItem });
82
34
  });
83
- // The chain has to outlive a failed write, or one backend rejection stops
84
- // every later write on this entry. The rejection itself is not swallowed: it
85
- // stays on the promise handed back to the caller that asked for the write.
35
+ // The chain must outlive a failed write; the rejection still reaches the caller through `write`.
86
36
  entryWrites = write.catch(() => undefined);
87
37
  return write;
88
38
  };
89
39
  const usePersistedState = (key, initialValue) => {
90
40
  const [state, setState] = (0, react_1.useState)(initialValue);
91
- // The setter must resolve updater functions against the last value applied,
92
- // not against the one captured by the render that created it. Reading the
93
- // render closure collapses updates batched into a single event.
41
+ // Updater functions must resolve against the last applied value, not the render closure's.
94
42
  const latestValue = (0, react_1.useRef)(state);
95
- // Whether anything has already put a value in place. A load that settles after
96
- // the caller set one must not revert it, and no signal local to the load can
97
- // answer this: the write it loses to happens outside the load entirely.
43
+ // A load that settles after the caller set a value must not revert it.
98
44
  const hasAppliedValue = (0, react_1.useRef)(false);
99
45
  const applyValue = (0, react_1.useCallback)((value) => {
100
46
  latestValue.current = value;
101
47
  hasAppliedValue.current = true;
102
48
  setState(value);
103
49
  }, []);
104
- // The entries this hook has written and not yet seen reported back.
105
- const pendingOwnWrites = (0, react_1.useRef)([]);
106
50
  const setPersistedState = (0, react_1.useCallback)(async (newState) => {
107
51
  const newValue = (0, get_new_value_1.default)(newState, latestValue.current);
108
- // Applied before the write is even queued: the caller sees its value at
109
- // once, and only the trip to storage waits its turn.
110
52
  applyValue(newValue);
111
- await commitEntry(key, newValue, pendingOwnWrites);
53
+ await commitEntry(key, newValue);
112
54
  }, [key, applyValue]);
113
- // As in `useState`, the value the load falls back to is the one given on the
114
- // first render. Later identities of an inline object must not reload, or the
115
- // effect re-runs on every render and never settles.
55
+ // The first render's initial value: reloading on a later identity would re-run the effect forever.
116
56
  const mountInitialValue = (0, react_1.useRef)(initialValue);
117
- // Subscribed before the load below, and the order is load-bearing: React runs
118
- // effects in declaration order, so reading first would leave an interval
119
- // between the read and the subscription in which a write belongs to neither
120
- // and is lost. Reading last covers everything written before the subscription
121
- // began, and the listener covers everything after.
122
- (0, use_storage_handler_1.default)(key, safeStorageKey, applyValue, storage, initialValue, pendingOwnWrites);
57
+ // Subscribed before the load: effects run in declaration order, and reading first would lose writes in between.
58
+ (0, use_storage_handler_1.default)(key, safeStorageKey, applyValue, storage, initialValue);
123
59
  (0, react_1.useEffect)(() => {
124
- // Two separate questions, and one cell cannot hold both: whether this load
125
- // is still the current one, which only the closure it belongs to can answer,
126
- // and whether a value has been applied meanwhile, which outlives it. A load
127
- // abandoned by a key change would otherwise read the flag its successor had
128
- // just set, apply the previous key's value and shut the successor out. The
129
- // second question is also what makes subscribing first safe: a value the
130
- // listener delivers while the load is in flight is not overwritten by it.
60
+ // Separate from `hasAppliedValue`: only this closure knows whether its own load is still current.
131
61
  let isCancelled = false;
132
62
  hasAppliedValue.current = false;
133
63
  const loadPersistedValue = async () => {
@@ -138,12 +68,7 @@ function createAsyncPersistedState(storageKey, storage) {
138
68
  applyValue((0, get_persisted_value_1.default)(key, mountInitialValue.current, persist[safeStorageKey]));
139
69
  }
140
70
  catch (err) {
141
- // An extension backend rejects on a quota error or an invalidated
142
- // extension context. Nothing awaits this load, so an unclaimed
143
- // rejection terminates the process on Node 15+ and surfaces as an
144
- // uncaught error in the browser. The initial value is already in
145
- // state, so the mount stands on it and the failure is reported rather
146
- // than swallowed, as the synchronous path reports its own.
71
+ // Nothing awaits this load, so an unclaimed rejection would surface as an uncaught error.
147
72
  console.error("use-persisted-state: Can't read value from storage", err);
148
73
  }
149
74
  };
@@ -1 +1 @@
1
- {"version":3,"file":"create-async-persisted-state.js","sourceRoot":"","sources":["../src/create-async-persisted-state.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,4CAkJC;AA5JD,iCAAgE;AAEhE,mFAA+E;AAC/E,0EAA+C;AAC/C,wEAA6C;AAC7C,sFAA2D;AAK3D,SAAwB,yBAAyB,CAC/C,UAAkB,EAClB,OAAU;IAEV,MAAM,cAAc,GAAG,wBAAwB,UAAU,EAAE,CAAA;IAE3D,8EAA8E;IAC9E,+EAA+E;IAC/E,4EAA4E;IAC5E,6EAA6E;IAC7E,8EAA8E;IAC9E,+EAA+E;IAC/E,2EAA2E;IAC3E,IAAI,WAAW,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAA;IAErD,MAAM,KAAK,GAAG,GAAkB,EAAE;QAChC,8EAA8E;QAC9E,wEAAwE;QACxE,8EAA8E;QAC9E,iDAAiD;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAA;QAEtE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAA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M,kBAAkB,GAAG,KAAK,IAAmB,EAAE;gBACnD,IAAI,CAAC;oBACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;oBAEjD,IAAI,WAAW,IAAI,eAAe,CAAC,OAAO;wBAAE,OAAM;oBAElD,UAAU,CAAC,IAAA,6BAAiB,EAAI,GAAG,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;gBAC3F,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,kEAAkE;oBAClE,+DAA+D;oBAC/D,kEAAkE;oBAClE,iEAAiE;oBACjE,sEAAsE;oBACtE,2DAA2D;oBAC3D,OAAO,CAAC,KAAK,CAAC,oDAAoD,EAAE,GAAG,CAAC,CAAA;gBAC1E,CAAC;YACH,CAAC,CAAA;YAED,kBAAkB,EAAE,CAAA;YAEpB,OAAO,GAAG,EAAE;gBACV,WAAW,GAAG,IAAI,CAAA;YACpB,CAAC,CAAA;QACH,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAA;QAErB,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;IACnC,CAAC,CAAA;IAED,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC"}
1
+ {"version":3,"file":"create-async-persisted-state.js","sourceRoot":"","sources":["../src/create-async-persisted-state.ts"],"names":[],"mappings":";;;;;AAWA,4CAsGC;AAhHD,iCAAgE;AAEhE,sFAA2D;AAC3D,0EAA+C;AAC/C,wEAA6C;AAC7C,sFAA2D;AAK3D,SAAwB,yBAAyB,CAC/C,UAAkB,EAClB,OAAU;IAEV,MAAM,cAAc,GAAG,wBAAwB,UAAU,EAAE,CAAA;IAE3D,wGAAwG;IACxG,IAAI,WAAW,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAA;IAErD,MAAM,KAAK,GAAG,GAAkB,EAAE;QAChC,wGAAwG;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AAK,CAAC,oDAAoD,EAAE,GAAG,CAAC,CAAA;gBAC1E,CAAC;YACH,CAAC,CAAA;YAED,kBAAkB,EAAE,CAAA;YAEpB,OAAO,GAAG,EAAE;gBACV,WAAW,GAAG,IAAI,CAAA;YACpB,CAAC,CAAA;QACH,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAA;QAErB,OAAO,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;IACnC,CAAC,CAAA;IAED,OAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create-persisted-state.d.ts","sourceRoot":"","sources":["../src/create-persisted-state.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AAOtE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC,CA0E/G"}
1
+ {"version":3,"file":"create-persisted-state.d.ts","sourceRoot":"","sources":["../src/create-persisted-state.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AAOtE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC,CA0D/G"}
@@ -1,44 +1,11 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.default = createPersistedState;
40
7
  const react_1 = require("react");
41
- const use_storage_handler_1 = __importStar(require("./utils/use-storage-handler"));
8
+ const use_storage_handler_1 = __importDefault(require("./utils/use-storage-handler"));
42
9
  const get_new_value_1 = __importDefault(require("./utils/get-new-value"));
43
10
  const get_new_item_1 = __importDefault(require("./utils/get-new-item"));
44
11
  const get_persisted_value_1 = __importDefault(require("./utils/get-persisted-value"));
@@ -49,30 +16,20 @@ function createPersistedState(storageKey, storage) {
49
16
  };
50
17
  const readPersisted = (key, initialValue) => (0, get_persisted_value_1.default)(key, initialValue, storage.get(safeStorageKey)[safeStorageKey]);
51
18
  const usePersistedState = (key, initialValue) => {
52
- // Reading through the initializer keeps the storage out of the render path:
53
- // the hook runs on every render of every consuming component, so a re-read is
54
- // only warranted when the key it is asked for actually changes.
19
+ // Read through the initializer: the hook runs on every render, so storage stays out of the render path.
55
20
  const [state, setState] = (0, react_1.useState)(() => readPersisted(key, initialValue));
56
- // The setter must resolve updater functions against the last value applied,
57
- // not against the one captured by the render that created it. Reading the
58
- // render closure collapses updates batched into a single event.
21
+ // Updater functions must resolve against the last applied value, not the render closure's.
59
22
  const latestValue = (0, react_1.useRef)(state);
60
23
  const applyValue = (0, react_1.useCallback)((value) => {
61
24
  latestValue.current = value;
62
25
  setState(value);
63
26
  }, []);
64
- // A mounted hook handed a different key has to show that key's value before
65
- // anything can be written, or the next update stores the previous key's value
66
- // under the new key and destroys what was there. Adjusting during render ties
67
- // the re-read to the change itself, where an effect would cost a read and a
68
- // second render on every mount as well.
27
+ // A new key must be read before anything is written, or the next update stores the old key's value under it.
69
28
  const renderedKey = (0, react_1.useRef)(key);
70
29
  if (renderedKey.current !== key) {
71
30
  renderedKey.current = key;
72
31
  applyValue(readPersisted(key, initialValue));
73
32
  }
74
- // The entries this hook has written and not yet seen reported back.
75
- const pendingOwnWrites = (0, react_1.useRef)([]);
76
33
  const setPersistedState = (0, react_1.useCallback)((newState) => {
77
34
  const newValue = (0, get_new_value_1.default)(newState, latestValue.current);
78
35
  applyValue(newValue);
@@ -82,16 +39,12 @@ function createPersistedState(storageKey, storage) {
82
39
  newItem = (0, get_new_item_1.default)(key, persistedItem, newValue);
83
40
  }
84
41
  catch {
85
- // Refused, and reported where it was refused. A write replaces the whole
86
- // entry, so an entry that cannot be read is one no write can be built on
87
- // without dropping every other hook's key; skipping leaves the bytes for
88
- // a repair to reach. The caller keeps what it set, unpersisted.
42
+ // A write replaces the whole entry, so an unreadable one is skipped rather than rebuilt without other keys.
89
43
  return;
90
44
  }
91
- (0, use_storage_handler_1.recordOwnWrite)(pendingOwnWrites, newItem);
92
45
  storage.set({ [safeStorageKey]: newItem });
93
46
  }, [key, applyValue]);
94
- (0, use_storage_handler_1.default)(key, safeStorageKey, applyValue, storage, initialValue, pendingOwnWrites);
47
+ (0, use_storage_handler_1.default)(key, safeStorageKey, applyValue, storage, initialValue);
95
48
  return [state, setPersistedState];
96
49
  };
97
50
  return [usePersistedState, clear];
@@ -1 +1 @@
1
- {"version":3,"file":"create-persisted-state.js","sourceRoot":"","sources":["../src/create-persisted-state.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,uCA0EC;AApFD,iCAAqD;AAKrD,mFAA+E;AAC/E,0EAA+C;AAC/C,wEAA6C;AAC7C,sFAA2D;AAE3D,SAAwB,oBAAoB,CAAC,UAAkB,EAAE,OAAgB;IAC/E,MAAM,cAAc,GAAG,wBAAwB,UAAU,EAAE,CAAA;IAC3D,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IAChC,CAAC,CAAA;IAED,MAAM,aAAa,GAAG,CAAI,GAAW,EAAE,YAAe,EAAK,EAAE,CAC3D,IAAA,6BAAiB,EAAI,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,CAAC,CAAA;IAEtF,MAAM,iBAAiB,GAAG,CAAI,GAAW,EAAE,YAAe,EAAwB,EAAE;QAClF,4EAA4E;QAC5E,8EAA8E;QAC9E,gEAAgE;QAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAI,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAA;QAE7E,4EAA4E;QAC5E,0EAA0E;QAC1E,gEAAgE;QAChE,MAAM,WAAW,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAA;QAEjC,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,CAAC,KAAQ,EAAQ,EAAE;YAChD,WAAW,CAAC,OAAO,GAAG,KAAK,CAAA;YAE3B,QAAQ,CAAC,KAAK,CAAC,CAA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 -1 +1 @@
1
- {"version":3,"file":"chrome-storage.d.ts","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AA+BrD,QAAA,MAAM,KAAK,cAA+C,CAAA;AAC1D,QAAA,MAAM,IAAI,cAA6C,CAAA;AACvD,QAAA,MAAM,OAAO,cAAmD,CAAA;AAEhE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"chrome-storage.d.ts","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAmBrD,QAAA,MAAM,KAAK,cAA+C,CAAA;AAC1D,QAAA,MAAM,IAAI,cAA6C,CAAA;AACvD,QAAA,MAAM,OAAO,cAAmD,CAAA;AAEhE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA"}
@@ -6,22 +6,13 @@ const registry = (0, extension_storage_1.createListenerRegistry)();
6
6
  chrome.storage.onChanged.addListener((changes, area) => {
7
7
  registry.fire((0, extension_storage_1.toStorageChanges)(changes), area);
8
8
  });
9
- // chrome.storage is callback-based, unlike its promise-based firefox counterpart.
9
+ // Passing no callback selects the promise form; the callback form leaves failures in `runtime.lastError`.
10
+ // Called through `storage`: a torn-off `StorageArea` method throws `Illegal invocation`, unlike firefox's.
11
+ // `get` stays `async` so asking whether this storage is asynchronous costs no round trip to the extension.
10
12
  const createStorage = (storage, area) => ({
11
- // Declared async, like the firefox adapter, so that asking whether this
12
- // storage is asynchronous can be answered from the function itself instead of
13
- // by calling it — a call here costs a round trip to the extension process.
14
- get: async (keys) => new Promise(resolve => {
15
- storage.get(keys, items => {
16
- resolve((0, extension_storage_1.toStoredItems)(items));
17
- });
18
- }),
19
- set: items => new Promise(resolve => {
20
- storage.set(items, resolve);
21
- }),
22
- remove: keys => new Promise(resolve => {
23
- storage.remove(keys, resolve);
24
- }),
13
+ get: async (keys) => (0, extension_storage_1.toStoredItems)(await storage.get(keys)),
14
+ set: items => storage.set(items),
15
+ remove: keys => storage.remove(keys),
25
16
  onChanged: registry.createOnChanged(area),
26
17
  });
27
18
  const local = createStorage(chrome.storage.local, 'local');
@@ -1 +1 @@
1
- {"version":3,"file":"chrome-storage.js","sourceRoot":"","sources":["../../src/storages/chrome-storage.ts"],"names":[],"mappings":";;;AACA,kEAA+G;AAE/G,MAAM,QAAQ,GAAG,IAAA,0CAAsB,GAAE,CAAA;AAEzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;IACrD,QAAQ,CAAC,IAAI,CAAC,IAAA,oCAAgB,EAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AAChD,CAAC,CAAC,CAAA;AAEF,kFAAkF;AAClF,MAAM,aAAa,GAAG,CAAC,OAAmC,EAAE,IAAU,EAAgB,EAAE,CAAC,CAAC;IACxF,wEAAwE;IACxE,8EAA8E;IAC9E,2EAA2E;IAC3E,GAAG,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE,CAChB,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;YACxB,OAAO,CAAC,IAAA,iCAAa,EAAC,KAAK,CAAC,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC;IACJ,GAAG,EAAE,KAAK,CAAC,EAAE,CACX,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC;IACJ,MAAM,EAAE,IAAI,CAAC,EAAE,CACb,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,CAAC,MAAM,CAAC,IAAI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AI,CAAC;CAC1C,CAAC,CAAA;AAEF,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;AAIjD,sBAAK;AAHd,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAGvC,oBAAI;AAFpB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE1C,0BAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";AAIA,wBAA4F"}
1
+ {"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";AAGA,wBAA4F"}
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const create_web_storage_1 = __importDefault(require("../utils/create-web-storage"));
7
- // The typeof guard keeps this import from throwing on server runtimes (SSR),
8
- // where the browser storage globals are not defined.
7
+ // The typeof guard keeps this import from throwing on server runtimes, where the global is not defined.
9
8
  exports.default = (0, create_web_storage_1.default)(typeof localStorage !== 'undefined' ? localStorage : undefined);
10
9
  //# sourceMappingURL=local-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,6EAA6E;AAC7E,qDAAqD;AACrD,kBAAe,IAAA,4BAAa,EAAC,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
1
+ {"version":3,"file":"local-storage.js","sourceRoot":"","sources":["../../src/storages/local-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,wGAAwG;AACxG,kBAAe,IAAA,4BAAa,EAAC,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";AAIA,wBAAgG"}
1
+ {"version":3,"file":"session-storage.d.ts","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";AAGA,wBAAgG"}
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const create_web_storage_1 = __importDefault(require("../utils/create-web-storage"));
7
- // The typeof guard keeps this import from throwing on server runtimes (SSR),
8
- // where the browser storage globals are not defined.
7
+ // The typeof guard keeps this import from throwing on server runtimes, where the global is not defined.
9
8
  exports.default = (0, create_web_storage_1.default)(typeof sessionStorage !== 'undefined' ? sessionStorage : undefined);
10
9
  //# sourceMappingURL=session-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,6EAA6E;AAC7E,qDAAqD;AACrD,kBAAe,IAAA,4BAAa,EAAC,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
1
+ {"version":3,"file":"session-storage.js","sourceRoot":"","sources":["../../src/storages/session-storage.ts"],"names":[],"mappings":";;;;;AAAA,qFAAuD;AAEvD,wGAAwG;AACxG,kBAAe,IAAA,4BAAa,EAAC,OAAO,cAAc,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA"}
@@ -6,13 +6,6 @@ export interface ChangeNotifier {
6
6
  hasListeners(): boolean;
7
7
  onChanged: StorageChangeEvent;
8
8
  }
9
- /**
10
- * Holds the subscribers of a single change source. Each adapter — and, for the
11
- * extension backends, each storage area — owns one, so a change never reaches
12
- * listeners that subscribed elsewhere.
13
- *
14
- * Routing a backend's events to the right notifier stays with the adapter: the
15
- * extensions demultiplex one event by area name, the DOM one by storage object.
16
- */
9
+ /** Holds the subscribers of a single change source, so a change never reaches listeners that subscribed elsewhere. */
17
10
  export declare function createChangeNotifier(): ChangeNotifier;
18
11
  //# sourceMappingURL=change-notifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"change-notifier.d.ts","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAyB,MAAM,mBAAmB,CAAA;AAEjG,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,GAAG,IAAI,CAAA;IACrD,YAAY,IAAI,OAAO,CAAA;IACvB,SAAS,EAAE,kBAAkB,CAAA;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CA0BrD"}
1
+ {"version":3,"file":"change-notifier.d.ts","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAyB,MAAM,mBAAmB,CAAA;AAEjG,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,GAAG,IAAI,CAAA;IACrD,YAAY,IAAI,OAAO,CAAA;IACvB,SAAS,EAAE,kBAAkB,CAAA;CAC9B;AAED,sHAAsH;AACtH,wBAAgB,oBAAoB,IAAI,cAAc,CAwBrD"}
@@ -1,14 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createChangeNotifier = createChangeNotifier;
4
- /**
5
- * Holds the subscribers of a single change source. Each adapter — and, for the
6
- * extension backends, each storage area — owns one, so a change never reaches
7
- * listeners that subscribed elsewhere.
8
- *
9
- * Routing a backend's events to the right notifier stays with the adapter: the
10
- * extensions demultiplex one event by area name, the DOM one by storage object.
11
- */
4
+ /** Holds the subscribers of a single change source, so a change never reaches listeners that subscribed elsewhere. */
12
5
  function createChangeNotifier() {
13
6
  const listeners = new Set();
14
7
  return {
@@ -17,8 +10,6 @@ function createChangeNotifier() {
17
10
  listener(changes);
18
11
  }
19
12
  },
20
- // Lets an adapter release a shared resource once nobody is listening; the
21
- // set behind onChanged stays the only count, so the two cannot drift.
22
13
  hasListeners() {
23
14
  return listeners.size > 0;
24
15
  },
@@ -1 +1 @@
1
- {"version":3,"file":"change-notifier.js","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":";;AAgBA,oDA0BC;AAlCD;;;;;;;GAOG;AACH,SAAgB,oBAAoB;IAClC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;IAElD,OAAO;QACL,IAAI,CAAC,OAAO;YACV,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,QAAQ,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QACD,0EAA0E;QAC1E,sEAAsE;QACtE,YAAY;YACV,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAA;QAC3B,CAAC;QACD,SAAS,EAAE;YACT,WAAW,CAAC,QAAQ;gBAClB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACzB,CAAC;YACD,cAAc,CAAC,QAAQ;gBACrB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC;YACD,WAAW,CAAC,QAAQ;gBAClB,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAChC,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"change-notifier.js","sourceRoot":"","sources":["../../src/utils/change-notifier.ts"],"names":[],"mappings":";;AASA,oDAwBC;AAzBD,sHAAsH;AACtH,SAAgB,oBAAoB;IAClC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAA;IAElD,OAAO;QACL,IAAI,CAAC,OAAO;YACV,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,QAAQ,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QACD,YAAY;YACV,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAA;QAC3B,CAAC;QACD,SAAS,EAAE;YACT,WAAW,CAAC,QAAQ;gBAClB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACzB,CAAC;YACD,cAAc,CAAC,QAAQ;gBACrB,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC;YACD,WAAW,CAAC,QAAQ;gBAClB,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAChC,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
@@ -1,12 +1,5 @@
1
1
  import type { Storage } from '../@types/storage';
2
- /**
3
- * Adapts a Web Storage area to the library's `Storage` contract.
4
- *
5
- * Pass `undefined` where the global is missing, as it is on a server: the
6
- * adapter then reads back nothing and **silently discards every write**, so a
7
- * consumer keeps its initial value instead of the import throwing. Listeners
8
- * are still accepted and reported, they simply never fire.
9
- */
2
+ /** Adapts a Web Storage area. With `undefined`, as on a server, it reads back nothing and discards every write. */
10
3
  declare const _default: (storage: globalThis.Storage | undefined) => Storage;
11
4
  export default _default;
12
5
  //# sourceMappingURL=create-web-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-web-storage.d.ts","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAqC,MAAM,mBAAmB,CAAA;AAQnF;;;;;;;GAOG;yBACa,SAAS,UAAU,CAAC,OAAO,GAAG,SAAS,KAAG,OAAO;AAAjE,wBAqFC"}
1
+ {"version":3,"file":"create-web-storage.d.ts","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAqC,MAAM,mBAAmB,CAAA;AAQnF,mHAAmH;yBACnG,SAAS,UAAU,CAAC,OAAO,GAAG,SAAS,KAAG,OAAO;AAAjE,wBAgFC"}
@@ -5,20 +5,11 @@ const storage_event_router_1 = require("./storage-event-router");
5
5
  function toKeyList(keys) {
6
6
  return Array.isArray(keys) ? keys : [keys];
7
7
  }
8
- /**
9
- * Adapts a Web Storage area to the library's `Storage` contract.
10
- *
11
- * Pass `undefined` where the global is missing, as it is on a server: the
12
- * adapter then reads back nothing and **silently discards every write**, so a
13
- * consumer keeps its initial value instead of the import throwing. Listeners
14
- * are still accepted and reported, they simply never fire.
15
- */
8
+ /** Adapts a Web Storage area. With `undefined`, as on a server, it reads back nothing and discards every write. */
16
9
  exports.default = (storage) => {
17
- // Per-instance notifier: the localStorage and sessionStorage adapters must not
18
- // share listeners, or a write to one area notifies subscribers of the other.
10
+ // Per instance: the localStorage and sessionStorage adapters must not share listeners.
19
11
  const notifier = (0, change_notifier_1.createChangeNotifier)();
20
- // Only a missing global is inert. Anything else a caller passes has to fail
21
- // on first use instead of swallowing their writes.
12
+ // Only a missing global is inert; anything else a caller passes has to fail on first use.
22
13
  if (storage === undefined) {
23
14
  return {
24
15
  get: () => ({}),
@@ -28,9 +19,7 @@ exports.default = (storage) => {
28
19
  };
29
20
  }
30
21
  const route = { storage, fire: notifier.fire };
31
- // The DOM subscription is shared and reference counted: an adapter joins it
32
- // with its first listener and lets go with its last, so factory calls nobody
33
- // listens to leave nothing attached to the global object.
22
+ // The DOM subscription is shared and reference counted, so adapters nobody listens to attach nothing.
34
23
  const onChanged = {
35
24
  addListener(listener) {
36
25
  notifier.onChanged.addListener(listener);
@@ -50,8 +39,7 @@ exports.default = (storage) => {
50
39
  const result = {};
51
40
  for (const key of toKeyList(keys)) {
52
41
  const item = storage.getItem(key);
53
- // `null` is the only answer that means absence: an empty string is a
54
- // value the caller stored, and reporting it as a missing key loses it.
42
+ // `null` is the only answer meaning absence; an empty string is a value the caller stored.
55
43
  if (item !== null)
56
44
  result[key] = item;
57
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"create-web-storage.js","sourceRoot":"","sources":["../../src/utils/create-web-storage.ts"],"names":[],"mappings":";;AACA,uDAAwD;AACxD,iEAAsF;AAEtF,SAAS,SAAS,CAAC,IAAuB;IACxC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,kBAAe,CAAC,OAAuC,EAAW,EAAE;IAClE,+EAA+E;IAC/E,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,IAAA,sCAAoB,GAAE,CAAA;IAEvC,4EAA4E;IAC5E,mDAAmD;IACnD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO;YACL,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;YACf,GAAG,EAAE,GAAG,EAAE,GAAE,CAAC;YACb,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;YAChB,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B,CAAA;IACH,CAAC;IAED,MAAM,KAAK,GAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAA;IAEjE,4EAA4E;IAC5E,6EAA6E;IAC7E,0DAA0D;IAC1D,MAAM,SAAS,GAAuB;QACpC,WAAW,CAAC,QAAQ;YAClB,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;YAExC,IAAA,+BAAQ,EAAC,KAAK,CAAC,CAAA;QACjB,CAAC;QACD,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QAAQ,EAAE,KAAK;iBAChB,CAAA;YACH,CAAC;YAED,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC7D,CAAC;QACD,MAAM,EAAE,IAAI,CAAC,EAAE;YACb,MAAM,OAAO,GAAqC,EAAE,CAAA;YAEpD,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;gBAErC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;gBAEvB,OAAO,CAAC,GAAG,CAAC,GAAG;oBACb,QAAQ;oBACR,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;YAED,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC7D,CAAC;QACD,SAAS;KACV,CAAA;AACH,CAAC,CAAA"}
@@ -1,12 +1,7 @@
1
1
  import type { StorageChange, StorageChangeEvent } from '../@types/storage';
2
2
  declare const TRACKED_AREAS: readonly ["local", "sync", "managed"];
3
3
  export type Area = (typeof TRACKED_AREAS)[number];
4
- /**
5
- * Extension storage holds arbitrary JSON, while this library only ever writes
6
- * serialized strings. Anything else under a key belongs to other code and is
7
- * reported as absent — which is what effectively happened before, once such a
8
- * value reached `JSON.parse` and the hook fell back to its initial value.
9
- */
4
+ /** Extension storage holds arbitrary JSON; this library writes only strings, so anything else reads as absent. */
10
5
  export declare function toStoredValue(value: unknown): string | null | undefined;
11
6
  export declare function toStorageChanges(changes: {
12
7
  [key: string]: {
@@ -27,12 +22,7 @@ export interface ListenerRegistry {
27
22
  }, area: string): void;
28
23
  createOnChanged(area: Area): StorageChangeEvent;
29
24
  }
30
- /**
31
- * Demultiplexes an extension's single `onChanged` event, which names the area
32
- * that changed, to one notifier per area. Each adapter owns its own registry,
33
- * so a change in one browser's storage never reaches listeners registered on
34
- * another's.
35
- */
25
+ /** Demultiplexes an extension's single `onChanged` event to one notifier per area, one registry per adapter. */
36
26
  export declare function createListenerRegistry(): ListenerRegistry;
37
27
  export {};
38
28
  //# sourceMappingURL=extension-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extension-storage.d.ts","sourceRoot":"","sources":["../../src/utils/extension-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAG1E,QAAA,MAAM,aAAa,uCAAwC,CAAA;AAE3D,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAQjD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAIvE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GAAG;IACxG,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAC7B,CAWA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAQ1F;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnE,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,CAAA;C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