react-wire-persisted 2.0.1 → 2.1.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/client.js +1 -1
- package/client.mjs +6 -5
- package/dist/index.js +208 -171
- package/dist/react-wire-persisted.js +208 -171
- package/dist/react-wire-persisted.umd.cjs +1 -1
- package/nextjs.js +4 -27
- package/package.json +82 -75
- package/src/components/HydrationProvider.js +3 -3
- package/src/components/HydrationProvider.jsx +2 -2
- package/src/components/index.js +1 -1
- package/src/hooks/useHydration.js +13 -25
- package/src/index.js +2 -2
- package/src/providers/LocalStorageProvider.js +40 -90
- package/src/providers/MemoryStorageProvider.js +3 -9
- package/src/providers/StorageProvider.js +13 -21
- package/src/react-wire-persisted.js +162 -37
- package/src/utils/fakeLocalStorage.js +3 -4
- package/src/utils/index.js +7 -9
- package/src/utils/isomorphic.js +19 -6
- package/src/utils/keys.js +14 -17
package/client.js
CHANGED
|
@@ -55,4 +55,4 @@ export function HydrationProvider({ children, onUpgrade, autoUpgrade = true }) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// Re-export the hook from the main package for convenience
|
|
58
|
-
export { useHydration } from './dist/react-wire-persisted.js'
|
|
58
|
+
export { useHydration } from './dist/react-wire-persisted.js'
|
package/client.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const isLocalStorageAvailable = () => {
|
|
|
16
16
|
window.localStorage.setItem(testKey, 'test')
|
|
17
17
|
window.localStorage.removeItem(testKey)
|
|
18
18
|
return true
|
|
19
|
-
} catch (
|
|
19
|
+
} catch (_) {
|
|
20
20
|
return false
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -30,10 +30,11 @@ const fakeStorage = {
|
|
|
30
30
|
},
|
|
31
31
|
removeItem: (key) => {
|
|
32
32
|
delete fakeStorage.data[key]
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Get current storage (real or fake)
|
|
37
|
+
// biome-ignore lint/correctness/noUnusedVariables: client usage only
|
|
37
38
|
const getCurrentStorage = () => {
|
|
38
39
|
return isLocalStorageAvailable() ? window.localStorage : fakeStorage
|
|
39
40
|
}
|
|
@@ -52,7 +53,7 @@ const upgradeStorageToReal = () => {
|
|
|
52
53
|
try {
|
|
53
54
|
// Move data from fake to real storage
|
|
54
55
|
const fakeData = { ...fakeStorage.data }
|
|
55
|
-
Object.keys(fakeData).forEach(key => {
|
|
56
|
+
Object.keys(fakeData).forEach((key) => {
|
|
56
57
|
if (fakeData[key] != null) {
|
|
57
58
|
window.localStorage.setItem(key, fakeData[key])
|
|
58
59
|
}
|
|
@@ -61,7 +62,7 @@ const upgradeStorageToReal = () => {
|
|
|
61
62
|
// Clear fake storage
|
|
62
63
|
fakeStorage.data = {}
|
|
63
64
|
return true
|
|
64
|
-
} catch (
|
|
65
|
+
} catch (_) {
|
|
65
66
|
return false
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -105,4 +106,4 @@ export function HydrationProvider({ children, onUpgrade, autoUpgrade = true }) {
|
|
|
105
106
|
}, [autoUpgrade, onUpgrade])
|
|
106
107
|
|
|
107
108
|
return children
|
|
108
|
-
}
|
|
109
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,74 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useRef as A, useEffect as T } from "react";
|
|
2
|
+
import { createWire as k } from "@forminator/react-wire";
|
|
3
3
|
(function() {
|
|
4
|
-
const
|
|
4
|
+
const e = {};
|
|
5
5
|
try {
|
|
6
6
|
if (process) {
|
|
7
|
-
process.env = Object.assign({}, process.env), Object.assign(process.env,
|
|
7
|
+
process.env = Object.assign({}, process.env), Object.assign(process.env, e);
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
} catch {
|
|
11
11
|
}
|
|
12
|
-
globalThis.process = { env:
|
|
12
|
+
globalThis.process = { env: e };
|
|
13
13
|
})();
|
|
14
|
-
const
|
|
15
|
-
y[s] = s;
|
|
16
|
-
}, j = (s) => w(s), x = () => y, N = (s, e = null) => {
|
|
17
|
-
const t = e || y;
|
|
18
|
-
return s ? Object.keys(t).reduce((r, o) => ({
|
|
19
|
-
...r,
|
|
20
|
-
[o]: `${s}.${t[o]}`
|
|
21
|
-
}), {}) : t;
|
|
22
|
-
}, g = {
|
|
14
|
+
const p = {
|
|
23
15
|
__IS_FAKE_LOCAL_STORAGE__: !0
|
|
24
|
-
},
|
|
25
|
-
getItem: (
|
|
26
|
-
setItem: (
|
|
27
|
-
|
|
16
|
+
}, S = {
|
|
17
|
+
getItem: (e) => p[e],
|
|
18
|
+
setItem: (e, t) => {
|
|
19
|
+
p[e] = t;
|
|
28
20
|
},
|
|
29
|
-
removeItem: (
|
|
30
|
-
delete
|
|
21
|
+
removeItem: (e) => {
|
|
22
|
+
delete p[e];
|
|
31
23
|
},
|
|
32
24
|
// Make Object.keys() work properly for _resetAll method
|
|
33
|
-
...
|
|
25
|
+
...p
|
|
34
26
|
};
|
|
35
|
-
let
|
|
36
|
-
typeof window < "u" && (
|
|
37
|
-
|
|
38
|
-
}) :
|
|
39
|
-
const
|
|
40
|
-
|
|
27
|
+
let w = !1, R = !1, O = !1;
|
|
28
|
+
typeof window < "u" && (w = !0, document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", () => {
|
|
29
|
+
R = !0;
|
|
30
|
+
}) : R = !0);
|
|
31
|
+
const u = () => w, I = () => R, b = () => O, U = () => {
|
|
32
|
+
O = !0;
|
|
33
|
+
}, y = () => {
|
|
34
|
+
if (!w) return !1;
|
|
41
35
|
try {
|
|
42
|
-
const
|
|
43
|
-
return window.localStorage.setItem(
|
|
36
|
+
const e = "__rwp_test__";
|
|
37
|
+
return window.localStorage.setItem(e, "test"), window.localStorage.removeItem(e), !0;
|
|
44
38
|
} catch {
|
|
45
39
|
return !1;
|
|
46
40
|
}
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
}, P = {}, N = (e) => {
|
|
42
|
+
P[e] = e;
|
|
43
|
+
}, F = (e) => N(e), x = () => P, K = (e, t = null) => {
|
|
44
|
+
const s = t || P;
|
|
45
|
+
return e ? Object.keys(s).reduce((r, n) => (r[n] = `${e}.${s[n]}`, r), {}) : s;
|
|
46
|
+
}, G = (e) => {
|
|
47
|
+
const t = typeof e;
|
|
48
|
+
return e === null ? !0 : Array.isArray(e) || t === "object" ? !1 : t !== "function";
|
|
49
|
+
}, z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
51
50
|
__proto__: null,
|
|
52
|
-
addKey:
|
|
53
|
-
fakeLocalStorage:
|
|
54
|
-
getHasHydrated:
|
|
55
|
-
|
|
51
|
+
addKey: N,
|
|
52
|
+
fakeLocalStorage: S,
|
|
53
|
+
getHasHydrated: I,
|
|
54
|
+
getHasHydratedStorage: b,
|
|
55
|
+
getIsClient: u,
|
|
56
56
|
getKeys: x,
|
|
57
|
-
getPrefixedKeys:
|
|
58
|
-
isLocalStorageAvailable:
|
|
59
|
-
isPrimitive:
|
|
60
|
-
key:
|
|
57
|
+
getPrefixedKeys: K,
|
|
58
|
+
isLocalStorageAvailable: y,
|
|
59
|
+
isPrimitive: G,
|
|
60
|
+
key: F,
|
|
61
|
+
markStorageAsHydrated: U
|
|
61
62
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
62
|
-
class
|
|
63
|
+
class E {
|
|
63
64
|
/**
|
|
64
65
|
* Initializes the class
|
|
65
66
|
* @param {String} namespace Namespace to prefix all keys with. Mostly used for the logging & reset functions
|
|
66
67
|
* @param {Object} registry (Optional) Initialize the storage provider with an existing registry
|
|
67
68
|
*/
|
|
68
|
-
constructor(
|
|
69
|
-
if (new.target ===
|
|
69
|
+
constructor(t, s) {
|
|
70
|
+
if (new.target === E)
|
|
70
71
|
throw TypeError("StorageProvider is abstract. Extend this class to implement it");
|
|
71
|
-
this.namespace =
|
|
72
|
+
this.namespace = t || null, this.registry = s || /* istanbul ignore next */
|
|
72
73
|
{};
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
@@ -77,22 +78,22 @@ class I {
|
|
|
77
78
|
* @param {String} namespace New namespace for this storage provider
|
|
78
79
|
*/
|
|
79
80
|
/* istanbul ignore next */
|
|
80
|
-
setNamespace(
|
|
81
|
+
setNamespace(t) {
|
|
81
82
|
}
|
|
82
83
|
/**
|
|
83
84
|
* Registers an item with it's initial value. This is used for logging, resetting, etc.
|
|
84
85
|
* @param {String} key Storage item's key
|
|
85
86
|
* @param {*} initialValue Storage item's initial value
|
|
86
87
|
*/
|
|
87
|
-
register(
|
|
88
|
-
this.registry[
|
|
88
|
+
register(t, s) {
|
|
89
|
+
this.registry[t] = s;
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
92
|
* Reads an item from storage
|
|
92
93
|
* @param {String} key Key for the item to retrieve
|
|
93
94
|
*/
|
|
94
95
|
/* istanbul ignore next */
|
|
95
|
-
getItem(
|
|
96
|
+
getItem(t) {
|
|
96
97
|
}
|
|
97
98
|
/**
|
|
98
99
|
* Stores a value
|
|
@@ -100,7 +101,7 @@ class I {
|
|
|
100
101
|
* @param {String} value Item's value to store
|
|
101
102
|
*/
|
|
102
103
|
/* istanbul ignore next */
|
|
103
|
-
setItem(
|
|
104
|
+
setItem(t, s) {
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* Removes an item from storage
|
|
@@ -108,7 +109,7 @@ class I {
|
|
|
108
109
|
* @param {Boolean} fromRegistry (Optional) If the item should also be removed from the registry
|
|
109
110
|
*/
|
|
110
111
|
/* istanbul ignore next */
|
|
111
|
-
removeItem(
|
|
112
|
+
removeItem(t, s = !1) {
|
|
112
113
|
}
|
|
113
114
|
/**
|
|
114
115
|
* Gets all stored keys & values
|
|
@@ -118,13 +119,13 @@ class I {
|
|
|
118
119
|
getAll() {
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
121
|
-
*
|
|
122
|
+
*
|
|
122
123
|
* @param {Boolean} useInitialValues If values should be replaced with their initial values. If false, keys are removed
|
|
123
124
|
* @param {String[]} excludedKeys (Optional) List of keys to exclude
|
|
124
125
|
* @param {Boolean} clearRegistry (Optional) If the registry should also be cleared
|
|
125
126
|
*/
|
|
126
127
|
/* istanbul ignore next */
|
|
127
|
-
_resetAll(
|
|
128
|
+
_resetAll(t = !0, s = [], r = !1) {
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Resets all values to their initial values
|
|
@@ -132,7 +133,7 @@ class I {
|
|
|
132
133
|
* @param {String[]} excludedKeys (Optional) List of keys to exclude
|
|
133
134
|
*/
|
|
134
135
|
/* istanbul ignore next */
|
|
135
|
-
resetAll(
|
|
136
|
+
resetAll(t = []) {
|
|
136
137
|
}
|
|
137
138
|
/**
|
|
138
139
|
* Removes all items from local storage.
|
|
@@ -140,81 +141,69 @@ class I {
|
|
|
140
141
|
* @param {String[]} excludedKeys (Optional) List of keys to exclude
|
|
141
142
|
*/
|
|
142
143
|
/* istanbul ignore next */
|
|
143
|
-
removeAll(
|
|
144
|
+
removeAll(t = []) {
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
|
-
class
|
|
147
|
-
constructor(
|
|
148
|
-
super(
|
|
147
|
+
class V extends E {
|
|
148
|
+
constructor(t = null, s = {}) {
|
|
149
|
+
super(t, s), this.storage = S, this._isUsingFakeStorage = !0;
|
|
149
150
|
}
|
|
150
151
|
getStorage() {
|
|
151
|
-
return
|
|
152
|
+
return y() ? window.localStorage : S;
|
|
152
153
|
}
|
|
153
|
-
setNamespace(
|
|
154
|
+
setNamespace(t) {
|
|
154
155
|
if (!this.namespace) {
|
|
155
|
-
this.namespace =
|
|
156
|
+
this.namespace = t;
|
|
156
157
|
return;
|
|
157
158
|
}
|
|
158
|
-
if (this.namespace ===
|
|
159
|
-
|
|
160
|
-
const t = JSON.parse(JSON.stringify(this.getAll()));
|
|
159
|
+
if (this.namespace === t) return;
|
|
160
|
+
const s = JSON.parse(JSON.stringify(this.getAll()));
|
|
161
161
|
this.removeAll();
|
|
162
|
-
for (const [r,
|
|
163
|
-
const
|
|
164
|
-
this.setItem(
|
|
162
|
+
for (const [r, n] of Object.entries(s)) {
|
|
163
|
+
const a = r.replace(this.namespace, t);
|
|
164
|
+
this.setItem(a, n);
|
|
165
165
|
}
|
|
166
|
-
this.namespace =
|
|
166
|
+
this.namespace = t;
|
|
167
167
|
}
|
|
168
|
-
getItem(
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
return null;
|
|
168
|
+
getItem(t) {
|
|
169
|
+
const s = this.storage.getItem(t);
|
|
170
|
+
if (s == null) return null;
|
|
172
171
|
try {
|
|
173
|
-
return JSON.parse(
|
|
172
|
+
return JSON.parse(s);
|
|
174
173
|
} catch {
|
|
175
|
-
return
|
|
174
|
+
return s;
|
|
176
175
|
}
|
|
177
176
|
}
|
|
178
|
-
setItem(
|
|
179
|
-
let r =
|
|
180
|
-
return r != null && (r =
|
|
177
|
+
setItem(t, s) {
|
|
178
|
+
let r = s;
|
|
179
|
+
return r != null && (r = G(s) ? s : JSON.stringify(s)), this.storage.setItem(t, r);
|
|
181
180
|
}
|
|
182
|
-
removeItem(
|
|
183
|
-
return
|
|
181
|
+
removeItem(t, s = !1) {
|
|
182
|
+
return s && delete this.registry[t], this.storage.removeItem(t);
|
|
184
183
|
}
|
|
185
184
|
getAll() {
|
|
186
|
-
const
|
|
187
|
-
return Object.keys(this.storage).reduce((
|
|
185
|
+
const t = `${this.namespace}.`;
|
|
186
|
+
return Object.keys(this.storage).reduce((s, r) => ((!this.namespace || r.startsWith(t)) && (s[r] = this.storage.getItem(r)), s), {});
|
|
188
187
|
}
|
|
189
|
-
_resetAll(
|
|
190
|
-
const
|
|
191
|
-
Object.keys(this.storage).forEach((
|
|
192
|
-
const
|
|
193
|
-
!
|
|
188
|
+
_resetAll(t = !0, s = [], r = !1) {
|
|
189
|
+
const n = `${this.namespace}.`;
|
|
190
|
+
Object.keys(this.storage).forEach((a) => {
|
|
191
|
+
const c = this.namespace ? a.startsWith(n) : !0, _ = s?.includes(a) || !1;
|
|
192
|
+
!c || _ || (t ? Object.hasOwn(this.registry, a) ? this.storage.setItem(a, this.registry[a]) : this.storage.removeItem(a) : (this.storage.removeItem(a), r && delete this.registry[a]));
|
|
194
193
|
});
|
|
195
194
|
}
|
|
196
|
-
resetAll(
|
|
197
|
-
this._resetAll(!0,
|
|
195
|
+
resetAll(t = [], s = !1) {
|
|
196
|
+
this._resetAll(!0, t || [], s);
|
|
198
197
|
}
|
|
199
|
-
removeAll(
|
|
200
|
-
this._resetAll(!1,
|
|
198
|
+
removeAll(t = [], s = !1) {
|
|
199
|
+
this._resetAll(!1, t || [], s);
|
|
201
200
|
}
|
|
202
201
|
/**
|
|
203
202
|
* Attempt to upgrade from fake storage to real localStorage
|
|
204
203
|
* This is useful for hydration scenarios
|
|
205
204
|
*/
|
|
206
205
|
upgradeToRealStorage() {
|
|
207
|
-
|
|
208
|
-
return !1;
|
|
209
|
-
const e = { ...this.storage };
|
|
210
|
-
return this.storage = window.localStorage, this._isUsingFakeStorage = !1, Object.keys(e).forEach((t) => {
|
|
211
|
-
if (t !== "__IS_FAKE_LOCAL_STORAGE__" && e[t] != null)
|
|
212
|
-
try {
|
|
213
|
-
this.storage.setItem(t, e[t]);
|
|
214
|
-
} catch {
|
|
215
|
-
return this.storage = h, this._isUsingFakeStorage = !0, !1;
|
|
216
|
-
}
|
|
217
|
-
}), !0;
|
|
206
|
+
return !this._isUsingFakeStorage || !y() ? !1 : (this.storage = window.localStorage, this._isUsingFakeStorage = !1, !0);
|
|
218
207
|
}
|
|
219
208
|
/**
|
|
220
209
|
* Check if currently using fake storage
|
|
@@ -223,87 +212,135 @@ class T extends I {
|
|
|
223
212
|
return this._isUsingFakeStorage;
|
|
224
213
|
}
|
|
225
214
|
}
|
|
226
|
-
const
|
|
215
|
+
const l = Math.random().toString(36).substring(7), i = (...e) => {
|
|
216
|
+
typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ !== !1 && console.log(...e);
|
|
217
|
+
}, v = {
|
|
227
218
|
logging: {
|
|
228
219
|
enabled: !1
|
|
229
220
|
}
|
|
230
221
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
},
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
222
|
+
typeof globalThis < "u" && globalThis.__RWP_LOGGING_ENABLED__ === void 0 && (globalThis.__RWP_LOGGING_ENABLED__ = v.logging.enabled);
|
|
223
|
+
i("[RWP] Module initialized, instance ID:", l);
|
|
224
|
+
const W = V;
|
|
225
|
+
i("[RWP] About to check global storage, instanceId:", l);
|
|
226
|
+
let o;
|
|
227
|
+
try {
|
|
228
|
+
globalThis.__RWP_STORAGE__ ? i("[RWP] Using existing global storage in instance:", l) : (i("[RWP] Creating global storage in instance:", l), globalThis.__RWP_STORAGE__ = new W()), o = globalThis.__RWP_STORAGE__, i("[RWP] Storage assigned successfully");
|
|
229
|
+
} catch (e) {
|
|
230
|
+
globalThis.__RWP_LOGGING_ENABLED__ && console.error("[RWP] Error setting up global storage:", e), o = new W();
|
|
231
|
+
}
|
|
232
|
+
let h = { ...v };
|
|
233
|
+
const m = [];
|
|
234
|
+
typeof globalThis < "u" && (globalThis.__RWP_REGISTERED_WIRES__ ? i("[RWP] Using existing global registeredWires in instance:", l) : (i("[RWP] Creating global registeredWires in instance:", l), globalThis.__RWP_REGISTERED_WIRES__ = /* @__PURE__ */ new Map()));
|
|
235
|
+
const g = globalThis.__RWP_REGISTERED_WIRES__ || /* @__PURE__ */ new Map();
|
|
236
|
+
i("[RWP] registeredWires Map reference in instance:", l, "size:", g.size);
|
|
237
|
+
const j = () => o.namespace, M = () => o, $ = () => h, B = (e) => {
|
|
238
|
+
i("[RWP] setNamespace() called with:", e, "registered wires before:", g.size), o.setNamespace(e), o = new W(e || j()), i("[RWP] setNamespace() done, registered wires after:", g.size);
|
|
239
|
+
}, J = (e) => {
|
|
240
|
+
if (h = {
|
|
241
|
+
...h,
|
|
242
|
+
...e
|
|
243
|
+
}, typeof globalThis < "u" && (globalThis.__RWP_LOGGING_ENABLED__ = h.logging.enabled), h.logging.enabled)
|
|
244
|
+
for (console.info("Flushing", m.length, "pending logs"); m.length; )
|
|
245
|
+
console.log(...m.shift());
|
|
246
|
+
}, C = () => {
|
|
247
|
+
i("[RWP] refreshAllWires() called in instance:", l, "registered wires:", g.size), f("react-wire-persisted: refreshAllWires() called, registered wires:", g.size), g.forEach((e, t) => {
|
|
248
|
+
const s = o.getItem(t), r = e.getValue();
|
|
249
|
+
i("[RWP] Checking wire", t, {
|
|
250
|
+
storedValue: s,
|
|
251
|
+
currentValue: r,
|
|
252
|
+
willUpdate: s !== null && s !== r
|
|
253
|
+
}), f("react-wire-persisted: Checking wire", t, {
|
|
254
|
+
storedValue: s,
|
|
255
|
+
currentValue: r,
|
|
256
|
+
willUpdate: s !== null && s !== r
|
|
257
|
+
}), s !== null && s !== r && (i("[RWP] Refreshing wire", t, "with stored value", s), f("react-wire-persisted: Refreshing wire", t, "with stored value", s), e.setValue(s));
|
|
258
|
+
});
|
|
259
|
+
}, L = () => {
|
|
260
|
+
if (i("[RWP] upgradeStorage() called in instance:", l, {
|
|
261
|
+
isClient: u(),
|
|
262
|
+
isUsingFakeStorage: o.isUsingFakeStorage()
|
|
263
|
+
}), f("react-wire-persisted: upgradeStorage() called", {
|
|
264
|
+
isClient: u(),
|
|
265
|
+
isUsingFakeStorage: o.isUsingFakeStorage()
|
|
266
|
+
}), !u()) return !1;
|
|
267
|
+
const e = o.upgradeToRealStorage();
|
|
268
|
+
return i("[RWP] upgradeToRealStorage() returned", e), f("react-wire-persisted: upgradeToRealStorage() returned", e), e && (U(), i("[RWP] Upgraded to real localStorage, calling refreshAllWires()"), f("react-wire-persisted: Upgraded to real localStorage after hydration"), C()), e;
|
|
269
|
+
}, f = (...e) => {
|
|
270
|
+
h.logging.enabled ? console.log(...e) : m.push(e);
|
|
271
|
+
}, q = (e, t = null) => {
|
|
272
|
+
if (i("[RWP] createPersistedWire() called in instance:", l, "key:", e, "value:", t), !e && typeof e != "number") throw new Error(`createPersistedWire: Key cannot be a falsey value (${e}}`);
|
|
273
|
+
o.register(e, t);
|
|
274
|
+
const s = k(t), r = () => s.getValue(), n = (d) => (i(
|
|
275
|
+
"[RWP] setValue called in instance:",
|
|
276
|
+
l,
|
|
277
|
+
"key:",
|
|
278
|
+
e,
|
|
279
|
+
"isUsingFakeStorage:",
|
|
280
|
+
o.isUsingFakeStorage()
|
|
281
|
+
), o.setItem(e, d), s.setValue(d)), a = (d) => {
|
|
282
|
+
s.subscribe(d);
|
|
283
|
+
};
|
|
284
|
+
let c = t;
|
|
285
|
+
const _ = b() || !o.isUsingFakeStorage();
|
|
286
|
+
if (_ && u()) {
|
|
287
|
+
const d = o.getItem(e);
|
|
288
|
+
d !== null && (c = d);
|
|
289
|
+
}
|
|
290
|
+
return f("react-wire-persisted: create", e, {
|
|
291
|
+
value: t,
|
|
292
|
+
initialValue: c,
|
|
293
|
+
hasHydratedStorage: b(),
|
|
294
|
+
isUsingFakeStorage: o.isUsingFakeStorage(),
|
|
295
|
+
canReadStorage: _
|
|
296
|
+
}), c !== t && n(c), g.set(e, {
|
|
297
|
+
getValue: r,
|
|
298
|
+
setValue: n,
|
|
299
|
+
subscribe: a
|
|
300
|
+
}), i("[RWP] Wire registered, total wires:", g.size, "keys:", Array.from(g.keys())), {
|
|
301
|
+
...s,
|
|
262
302
|
getValue: r,
|
|
263
|
-
setValue:
|
|
264
|
-
subscribe:
|
|
303
|
+
setValue: n,
|
|
304
|
+
subscribe: a
|
|
265
305
|
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return O(() => {
|
|
272
|
-
if (!e || r.current || !m())
|
|
306
|
+
};
|
|
307
|
+
function Q({ children: e, onUpgrade: t, autoUpgrade: s = !0 }) {
|
|
308
|
+
const r = A(!1);
|
|
309
|
+
return T(() => {
|
|
310
|
+
if (!s || r.current || !u())
|
|
273
311
|
return;
|
|
274
|
-
const
|
|
275
|
-
|
|
312
|
+
const n = () => {
|
|
313
|
+
I() && !r.current && L() && (r.current = !0, t?.());
|
|
314
|
+
};
|
|
315
|
+
n();
|
|
316
|
+
const a = setTimeout(n, 0);
|
|
317
|
+
return () => clearTimeout(a);
|
|
318
|
+
}, [s, t]), e;
|
|
319
|
+
}
|
|
320
|
+
const X = (e = {}) => {
|
|
321
|
+
const { autoUpgrade: t = !0, onUpgrade: s } = e, r = A(!1);
|
|
322
|
+
return T(() => {
|
|
323
|
+
if (!t || r.current || !u()) return;
|
|
324
|
+
const n = () => {
|
|
325
|
+
I() && !r.current && L() && (r.current = !0, s?.());
|
|
276
326
|
};
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
return () => clearTimeout(
|
|
280
|
-
}, [
|
|
327
|
+
n();
|
|
328
|
+
const a = setTimeout(n, 0);
|
|
329
|
+
return () => clearTimeout(a);
|
|
330
|
+
}, [t, s]), {
|
|
281
331
|
hasUpgraded: r.current
|
|
282
332
|
};
|
|
283
333
|
};
|
|
284
|
-
function D({ children: s, onUpgrade: e, autoUpgrade: t = !0 }) {
|
|
285
|
-
const r = b(!1);
|
|
286
|
-
return O(() => {
|
|
287
|
-
if (!t || r.current || !m())
|
|
288
|
-
return;
|
|
289
|
-
const o = () => {
|
|
290
|
-
_() && !r.current && K() && (r.current = !0, e?.());
|
|
291
|
-
};
|
|
292
|
-
o();
|
|
293
|
-
const n = setTimeout(o, 0);
|
|
294
|
-
return () => clearTimeout(n);
|
|
295
|
-
}, [t, e]), s;
|
|
296
|
-
}
|
|
297
334
|
export {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
335
|
+
Q as HydrationProvider,
|
|
336
|
+
q as createPersistedWire,
|
|
337
|
+
v as defaultOptions,
|
|
338
|
+
j as getNamespace,
|
|
302
339
|
$ as getOptions,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
340
|
+
M as getStorage,
|
|
341
|
+
B as setNamespace,
|
|
342
|
+
J as setOptions,
|
|
343
|
+
L as upgradeStorage,
|
|
344
|
+
X as useHydration,
|
|
345
|
+
z as utils
|
|
309
346
|
};
|