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