storion 0.8.3 → 0.10.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/CHANGELOG.md +127 -21
- package/README.md +42 -2021
- package/dist/async/abortable.d.ts +295 -0
- package/dist/async/abortable.d.ts.map +1 -0
- package/dist/async/async.d.ts +86 -5
- package/dist/async/async.d.ts.map +1 -1
- package/dist/async/context.d.ts +15 -0
- package/dist/async/context.d.ts.map +1 -0
- package/dist/async/index.d.ts +16 -3
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +407 -137
- package/dist/async/safe.d.ts +221 -0
- package/dist/async/safe.d.ts.map +1 -0
- package/dist/async/types.d.ts +77 -29
- package/dist/async/types.d.ts.map +1 -1
- package/dist/async/wrappers.d.ts +217 -0
- package/dist/async/wrappers.d.ts.map +1 -0
- package/dist/core/effect.d.ts +34 -26
- package/dist/core/effect.d.ts.map +1 -1
- package/dist/core/equality.d.ts +25 -0
- package/dist/core/equality.d.ts.map +1 -1
- package/dist/core/focus.d.ts +20 -0
- package/dist/core/focus.d.ts.map +1 -0
- package/dist/core/focusHelpers.d.ts +258 -0
- package/dist/core/focusHelpers.d.ts.map +1 -0
- package/dist/core/middleware.d.ts +4 -4
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/storeContext.d.ts +2 -9
- package/dist/core/storeContext.d.ts.map +1 -1
- package/dist/dev.d.ts +0 -10
- package/dist/dev.d.ts.map +1 -1
- package/dist/{index-C8B6Mo8r.js → effect-BDQU8Voz.js} +1241 -583
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/network/index.d.ts +69 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/retry.d.ts +53 -0
- package/dist/network/retry.d.ts.map +1 -0
- package/dist/network/services.d.ts +58 -0
- package/dist/network/services.d.ts.map +1 -0
- package/dist/network/store.d.ts +36 -0
- package/dist/network/store.d.ts.map +1 -0
- package/dist/network/utils.d.ts +9 -0
- package/dist/network/utils.d.ts.map +1 -0
- package/dist/persist/index.d.ts +1 -1
- package/dist/persist/index.d.ts.map +1 -1
- package/dist/persist/index.js +55 -31
- package/dist/persist/persist.d.ts +119 -62
- package/dist/persist/persist.d.ts.map +1 -1
- package/dist/pool.d.ts +77 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +245 -244
- package/dist/react/stable.d.ts +27 -0
- package/dist/react/stable.d.ts.map +1 -0
- package/dist/react/useStore.d.ts +38 -13
- package/dist/react/useStore.d.ts.map +1 -1
- package/dist/react/withStore.d.ts.map +1 -1
- package/dist/storion.js +911 -37
- package/dist/trigger.d.ts +12 -7
- package/dist/trigger.d.ts.map +1 -1
- package/dist/types.d.ts +133 -22
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/storeTuple.d.ts +7 -0
- package/dist/utils/storeTuple.d.ts.map +1 -0
- package/package.json +5 -1
- package/dist/collection.d.ts +0 -34
- package/dist/collection.d.ts.map +0 -1
- package/dist/core/proxy.d.ts +0 -47
- package/dist/core/proxy.d.ts.map +0 -1
- package/dist/effect-C6h0PDDI.js +0 -446
- package/dist/isPromiseLike-bFkfHAbm.js +0 -6
- package/dist/react/useLocalStore.d.ts +0 -48
- package/dist/react/useLocalStore.d.ts.map +0 -1
package/dist/effect-C6h0PDDI.js
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
import { e as emitter } from "./emitter-j4rC71vY.js";
|
|
2
|
-
import { i as isPromiseLike } from "./isPromiseLike-bFkfHAbm.js";
|
|
3
|
-
class StorionError extends Error {
|
|
4
|
-
constructor(message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = "StorionError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
class SetupPhaseError extends StorionError {
|
|
10
|
-
constructor(method, hint) {
|
|
11
|
-
super(
|
|
12
|
-
`${method}() can only be called during setup phase. Do not call ${method}() inside actions or async callbacks.` + (hint ? ` ${hint}` : "")
|
|
13
|
-
);
|
|
14
|
-
this.name = "SetupPhaseError";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class LifetimeMismatchError extends StorionError {
|
|
18
|
-
constructor(parentName, childName, operation) {
|
|
19
|
-
super(
|
|
20
|
-
`Lifetime mismatch: Store "${parentName}" (keepAlive) cannot ${operation} store "${childName}" (autoDispose). A long-lived store cannot ${operation} a store that may be disposed. Either change "${parentName}" to autoDispose, or change "${childName}" to keepAlive.`
|
|
21
|
-
);
|
|
22
|
-
this.name = "LifetimeMismatchError";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
class AsyncFunctionError extends StorionError {
|
|
26
|
-
constructor(context, hint) {
|
|
27
|
-
super(`${context} must be synchronous. ${hint}`);
|
|
28
|
-
this.name = "AsyncFunctionError";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
class StoreDisposedError extends StorionError {
|
|
32
|
-
constructor(storeId) {
|
|
33
|
-
super(`Cannot call action on disposed store: ${storeId}`);
|
|
34
|
-
this.name = "StoreDisposedError";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
class InvalidActionError extends StorionError {
|
|
38
|
-
constructor(actionName, actualType) {
|
|
39
|
-
super(
|
|
40
|
-
`Action "${actionName}" must be a function, got ${actualType}. If using focus(), destructure it and return the getter/setter separately: const [get, set] = focus("path"); return { get, set };`
|
|
41
|
-
);
|
|
42
|
-
this.name = "InvalidActionError";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
class HooksContextError extends StorionError {
|
|
46
|
-
constructor(method, requiredContext) {
|
|
47
|
-
super(
|
|
48
|
-
`${method}() must be called inside ${requiredContext}. It requires an active tracking context.`
|
|
49
|
-
);
|
|
50
|
-
this.name = "HooksContextError";
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class ProviderMissingError extends StorionError {
|
|
54
|
-
constructor(hook, provider) {
|
|
55
|
-
super(`${hook} must be used within a ${provider}`);
|
|
56
|
-
this.name = "ProviderMissingError";
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
class LocalStoreDependencyError extends StorionError {
|
|
60
|
-
constructor(storeName, dependencyCount) {
|
|
61
|
-
super(
|
|
62
|
-
`Local store must not have dependencies, but "${storeName}" has ${dependencyCount} dependencies. Use useStore() with a global container for stores with dependencies.`
|
|
63
|
-
);
|
|
64
|
-
this.name = "LocalStoreDependencyError";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
class EffectRefreshError extends StorionError {
|
|
68
|
-
constructor() {
|
|
69
|
-
super("Effect is already running, cannot refresh");
|
|
70
|
-
this.name = "EffectRefreshError";
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
let globalHooks = {
|
|
74
|
-
scheduleNotification(notify) {
|
|
75
|
-
notify();
|
|
76
|
-
},
|
|
77
|
-
scheduleEffect(runEffect) {
|
|
78
|
-
runEffect();
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
function getHooks() {
|
|
82
|
-
return globalHooks;
|
|
83
|
-
}
|
|
84
|
-
function hasReadHook() {
|
|
85
|
-
return globalHooks.onRead !== void 0;
|
|
86
|
-
}
|
|
87
|
-
function hasWriteHook() {
|
|
88
|
-
return globalHooks.onWrite !== void 0;
|
|
89
|
-
}
|
|
90
|
-
function withHooks(hooksOrSetup, fn, onFinish) {
|
|
91
|
-
const prev = globalHooks;
|
|
92
|
-
if (typeof hooksOrSetup === "function") {
|
|
93
|
-
globalHooks = {
|
|
94
|
-
...globalHooks,
|
|
95
|
-
...hooksOrSetup(prev)
|
|
96
|
-
};
|
|
97
|
-
} else {
|
|
98
|
-
globalHooks = { ...prev, ...hooksOrSetup };
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
return fn();
|
|
102
|
-
} finally {
|
|
103
|
-
globalHooks = prev;
|
|
104
|
-
onFinish == null ? void 0 : onFinish();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function trackRead(storeId, prop, value, subscribe) {
|
|
108
|
-
var _a;
|
|
109
|
-
const key = `${storeId}.${prop}`;
|
|
110
|
-
(_a = globalHooks.onRead) == null ? void 0 : _a.call(globalHooks, { key, value, subscribe });
|
|
111
|
-
}
|
|
112
|
-
function trackWrite(storeId, prop, next, prev) {
|
|
113
|
-
var _a;
|
|
114
|
-
const key = `${storeId}.${prop}`;
|
|
115
|
-
(_a = globalHooks.onWrite) == null ? void 0 : _a.call(globalHooks, { key, next, prev });
|
|
116
|
-
}
|
|
117
|
-
function untrack(fn) {
|
|
118
|
-
return withHooks({ onRead: void 0, onWrite: void 0 }, fn);
|
|
119
|
-
}
|
|
120
|
-
function scheduleNotification(notify, key) {
|
|
121
|
-
globalHooks.scheduleNotification(notify, key);
|
|
122
|
-
}
|
|
123
|
-
function batch(fn) {
|
|
124
|
-
const pending = /* @__PURE__ */ new Map();
|
|
125
|
-
return withHooks(
|
|
126
|
-
(current) => ({
|
|
127
|
-
...current,
|
|
128
|
-
scheduleNotification: (notify, key) => {
|
|
129
|
-
const actualKey = key ?? notify;
|
|
130
|
-
pending.set(actualKey, notify);
|
|
131
|
-
}
|
|
132
|
-
}),
|
|
133
|
-
fn,
|
|
134
|
-
// Flush on finish
|
|
135
|
-
() => {
|
|
136
|
-
for (const notify of pending.values()) {
|
|
137
|
-
notify();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
function createEffectContext(nth, onRefresh) {
|
|
143
|
-
let cleanupEmitter = null;
|
|
144
|
-
let abortController = null;
|
|
145
|
-
let isStale = false;
|
|
146
|
-
const runCleanups = () => {
|
|
147
|
-
if (isStale) return;
|
|
148
|
-
isStale = true;
|
|
149
|
-
if (abortController) {
|
|
150
|
-
abortController.abort();
|
|
151
|
-
abortController = null;
|
|
152
|
-
}
|
|
153
|
-
if (cleanupEmitter && cleanupEmitter.size > 0) {
|
|
154
|
-
cleanupEmitter.emitAndClearLifo();
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
function wrapPromise(promise) {
|
|
158
|
-
return new Promise((resolve, reject) => {
|
|
159
|
-
promise.then(
|
|
160
|
-
(value) => {
|
|
161
|
-
if (!isStale) {
|
|
162
|
-
resolve(value);
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
(error) => {
|
|
166
|
-
if (!isStale) {
|
|
167
|
-
reject(error);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
const context = {
|
|
174
|
-
nth,
|
|
175
|
-
get signal() {
|
|
176
|
-
if (!abortController) {
|
|
177
|
-
abortController = new AbortController();
|
|
178
|
-
}
|
|
179
|
-
return abortController.signal;
|
|
180
|
-
},
|
|
181
|
-
onCleanup(listener) {
|
|
182
|
-
if (!cleanupEmitter) {
|
|
183
|
-
cleanupEmitter = emitter();
|
|
184
|
-
}
|
|
185
|
-
return cleanupEmitter.on(listener);
|
|
186
|
-
},
|
|
187
|
-
safe(promiseOrCallback) {
|
|
188
|
-
if (promiseOrCallback instanceof Promise) {
|
|
189
|
-
return wrapPromise(promiseOrCallback);
|
|
190
|
-
}
|
|
191
|
-
return (...args) => {
|
|
192
|
-
if (!isStale) {
|
|
193
|
-
const result = promiseOrCallback(
|
|
194
|
-
...args
|
|
195
|
-
);
|
|
196
|
-
if (isPromiseLike(result)) {
|
|
197
|
-
return wrapPromise(result);
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
return void 0;
|
|
202
|
-
};
|
|
203
|
-
},
|
|
204
|
-
refresh() {
|
|
205
|
-
if (!isStale) {
|
|
206
|
-
onRefresh();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
return Object.assign(context, { _runCleanups: runCleanups });
|
|
211
|
-
}
|
|
212
|
-
function resolveErrorStrategy(effectOptions) {
|
|
213
|
-
return (effectOptions == null ? void 0 : effectOptions.onError) ?? "keepAlive";
|
|
214
|
-
}
|
|
215
|
-
function getRetryDelay(config, attempt) {
|
|
216
|
-
if (typeof config.delay === "function") {
|
|
217
|
-
return config.delay(attempt);
|
|
218
|
-
}
|
|
219
|
-
return config.delay ?? 100 * Math.pow(2, attempt);
|
|
220
|
-
}
|
|
221
|
-
function effect(fn, options) {
|
|
222
|
-
let currentContext = null;
|
|
223
|
-
let subscriptionEmitter = null;
|
|
224
|
-
let isStarted = false;
|
|
225
|
-
let isRunning = false;
|
|
226
|
-
let isDisposed = false;
|
|
227
|
-
let runGeneration = 0;
|
|
228
|
-
let retryCount = 0;
|
|
229
|
-
let retryTimeout = null;
|
|
230
|
-
let errorStrategy = "keepAlive";
|
|
231
|
-
let onErrorCallback = null;
|
|
232
|
-
let prevTrackedDeps = /* @__PURE__ */ new Map();
|
|
233
|
-
let prevSubscriptionEmitter = null;
|
|
234
|
-
let trackedDeps = /* @__PURE__ */ new Map();
|
|
235
|
-
const writtenProps = /* @__PURE__ */ new Set();
|
|
236
|
-
let newTrackedDeps = null;
|
|
237
|
-
const getSubscriptionEmitter = () => {
|
|
238
|
-
if (!subscriptionEmitter) {
|
|
239
|
-
subscriptionEmitter = emitter();
|
|
240
|
-
}
|
|
241
|
-
return subscriptionEmitter;
|
|
242
|
-
};
|
|
243
|
-
const clearSubscriptions = () => {
|
|
244
|
-
if (subscriptionEmitter && subscriptionEmitter.size > 0) {
|
|
245
|
-
subscriptionEmitter.emitAndClear();
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
const areDepsChanged = (prev, next) => {
|
|
249
|
-
if (prev.size !== next.size) return true;
|
|
250
|
-
for (const key of next.keys()) {
|
|
251
|
-
if (!prev.has(key)) return true;
|
|
252
|
-
}
|
|
253
|
-
return false;
|
|
254
|
-
};
|
|
255
|
-
const subscribeToTrackedDeps = () => {
|
|
256
|
-
for (const [key, dep] of trackedDeps) {
|
|
257
|
-
if (writtenProps.has(key)) continue;
|
|
258
|
-
const unsub = dep.subscribe(() => {
|
|
259
|
-
scheduleNotification(execute, fn);
|
|
260
|
-
});
|
|
261
|
-
getSubscriptionEmitter().on(unsub);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
const handleError = (error) => {
|
|
265
|
-
onErrorCallback == null ? void 0 : onErrorCallback(error);
|
|
266
|
-
if (errorStrategy === "failFast") {
|
|
267
|
-
throw error;
|
|
268
|
-
}
|
|
269
|
-
if (errorStrategy === "keepAlive") {
|
|
270
|
-
console.error("Effect error (keepAlive):", error);
|
|
271
|
-
if (prevSubscriptionEmitter && prevSubscriptionEmitter.size > 0) {
|
|
272
|
-
trackedDeps = new Map(prevTrackedDeps);
|
|
273
|
-
subscriptionEmitter = prevSubscriptionEmitter;
|
|
274
|
-
prevSubscriptionEmitter = null;
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (newTrackedDeps && newTrackedDeps.size > 0) {
|
|
278
|
-
trackedDeps = newTrackedDeps;
|
|
279
|
-
}
|
|
280
|
-
subscribeToTrackedDeps();
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (typeof errorStrategy === "function") {
|
|
284
|
-
const retry = () => {
|
|
285
|
-
retryCount++;
|
|
286
|
-
execute();
|
|
287
|
-
};
|
|
288
|
-
errorStrategy({ error, retry, retryCount });
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
const retryConfig = errorStrategy;
|
|
292
|
-
if (retryCount < retryConfig.maxRetries) {
|
|
293
|
-
const delay = getRetryDelay(retryConfig, retryCount);
|
|
294
|
-
retryCount++;
|
|
295
|
-
retryTimeout = setTimeout(() => {
|
|
296
|
-
retryTimeout = null;
|
|
297
|
-
execute();
|
|
298
|
-
}, delay);
|
|
299
|
-
} else {
|
|
300
|
-
console.error(
|
|
301
|
-
`Effect failed after ${retryConfig.maxRetries} retries:`,
|
|
302
|
-
error
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
let cachedHooks = null;
|
|
307
|
-
const getTrackingHooks = (current) => {
|
|
308
|
-
if (!cachedHooks) {
|
|
309
|
-
cachedHooks = {
|
|
310
|
-
...current,
|
|
311
|
-
onRead: (event) => {
|
|
312
|
-
var _a;
|
|
313
|
-
(_a = current.onRead) == null ? void 0 : _a.call(current, event);
|
|
314
|
-
if (!newTrackedDeps.has(event.key)) {
|
|
315
|
-
newTrackedDeps.set(event.key, {
|
|
316
|
-
key: event.key,
|
|
317
|
-
value: event.value,
|
|
318
|
-
subscribe: event.subscribe
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
onWrite: (event) => {
|
|
323
|
-
var _a;
|
|
324
|
-
(_a = current.onWrite) == null ? void 0 : _a.call(current, event);
|
|
325
|
-
writtenProps.add(event.key);
|
|
326
|
-
},
|
|
327
|
-
scheduleNotification: current.scheduleNotification,
|
|
328
|
-
scheduleEffect: current.scheduleEffect
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
return cachedHooks;
|
|
332
|
-
};
|
|
333
|
-
const execute = () => {
|
|
334
|
-
if (isDisposed || isRunning) return;
|
|
335
|
-
isRunning = true;
|
|
336
|
-
let shouldRefresh = false;
|
|
337
|
-
const currentGeneration = ++runGeneration;
|
|
338
|
-
try {
|
|
339
|
-
currentContext == null ? void 0 : currentContext._runCleanups();
|
|
340
|
-
currentContext = null;
|
|
341
|
-
if (subscriptionEmitter && subscriptionEmitter.size > 0) {
|
|
342
|
-
prevTrackedDeps = new Map(trackedDeps);
|
|
343
|
-
prevSubscriptionEmitter = subscriptionEmitter;
|
|
344
|
-
subscriptionEmitter = null;
|
|
345
|
-
}
|
|
346
|
-
newTrackedDeps = /* @__PURE__ */ new Map();
|
|
347
|
-
writtenProps.clear();
|
|
348
|
-
let lazyContext = null;
|
|
349
|
-
if (fn.length) {
|
|
350
|
-
lazyContext = createEffectContext(currentGeneration, () => {
|
|
351
|
-
if (isRunning) {
|
|
352
|
-
throw new EffectRefreshError();
|
|
353
|
-
}
|
|
354
|
-
execute();
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
withHooks(getTrackingHooks, () => {
|
|
358
|
-
const result = fn(lazyContext);
|
|
359
|
-
if (result !== null && result !== void 0 && typeof result.then === "function") {
|
|
360
|
-
throw new AsyncFunctionError(
|
|
361
|
-
"Effect function",
|
|
362
|
-
"Use ctx.safe(promise) for async operations instead of returning a Promise."
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if (lazyContext && lazyContext.refresh === result) {
|
|
366
|
-
shouldRefresh = true;
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
currentContext = lazyContext;
|
|
370
|
-
retryCount = 0;
|
|
371
|
-
const depsChanged = areDepsChanged(trackedDeps, newTrackedDeps);
|
|
372
|
-
if (depsChanged) {
|
|
373
|
-
if (prevSubscriptionEmitter && prevSubscriptionEmitter.size > 0) {
|
|
374
|
-
prevSubscriptionEmitter.emitAndClear();
|
|
375
|
-
}
|
|
376
|
-
trackedDeps = newTrackedDeps;
|
|
377
|
-
subscribeToTrackedDeps();
|
|
378
|
-
} else {
|
|
379
|
-
if (prevSubscriptionEmitter) {
|
|
380
|
-
subscriptionEmitter = prevSubscriptionEmitter;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
prevTrackedDeps.clear();
|
|
384
|
-
prevSubscriptionEmitter = null;
|
|
385
|
-
} catch (error) {
|
|
386
|
-
if (error instanceof EffectRefreshError) {
|
|
387
|
-
throw error;
|
|
388
|
-
}
|
|
389
|
-
handleError(error);
|
|
390
|
-
} finally {
|
|
391
|
-
isRunning = false;
|
|
392
|
-
}
|
|
393
|
-
if (shouldRefresh) {
|
|
394
|
-
execute();
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
const dispose = () => {
|
|
398
|
-
if (isDisposed) return;
|
|
399
|
-
isDisposed = true;
|
|
400
|
-
runGeneration++;
|
|
401
|
-
if (retryTimeout) {
|
|
402
|
-
clearTimeout(retryTimeout);
|
|
403
|
-
retryTimeout = null;
|
|
404
|
-
}
|
|
405
|
-
currentContext == null ? void 0 : currentContext._runCleanups();
|
|
406
|
-
currentContext = null;
|
|
407
|
-
clearSubscriptions();
|
|
408
|
-
if (prevSubscriptionEmitter && prevSubscriptionEmitter.size > 0) {
|
|
409
|
-
prevSubscriptionEmitter.emitAndClear();
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
const start = (runOptions) => {
|
|
413
|
-
if (isStarted) return;
|
|
414
|
-
isStarted = true;
|
|
415
|
-
errorStrategy = resolveErrorStrategy(options);
|
|
416
|
-
onErrorCallback = (runOptions == null ? void 0 : runOptions.onError) ?? null;
|
|
417
|
-
execute();
|
|
418
|
-
};
|
|
419
|
-
getHooks().scheduleEffect((runOptions) => {
|
|
420
|
-
start(runOptions);
|
|
421
|
-
return dispose;
|
|
422
|
-
});
|
|
423
|
-
return dispose;
|
|
424
|
-
}
|
|
425
|
-
export {
|
|
426
|
-
AsyncFunctionError as A,
|
|
427
|
-
EffectRefreshError as E,
|
|
428
|
-
HooksContextError as H,
|
|
429
|
-
InvalidActionError as I,
|
|
430
|
-
LocalStoreDependencyError as L,
|
|
431
|
-
ProviderMissingError as P,
|
|
432
|
-
StorionError as S,
|
|
433
|
-
SetupPhaseError as a,
|
|
434
|
-
batch as b,
|
|
435
|
-
LifetimeMismatchError as c,
|
|
436
|
-
StoreDisposedError as d,
|
|
437
|
-
effect as e,
|
|
438
|
-
hasWriteHook as f,
|
|
439
|
-
trackWrite as g,
|
|
440
|
-
hasReadHook as h,
|
|
441
|
-
getHooks as i,
|
|
442
|
-
scheduleNotification as s,
|
|
443
|
-
trackRead as t,
|
|
444
|
-
untrack as u,
|
|
445
|
-
withHooks as w
|
|
446
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ActionsBase, StateBase, StoreInstance, StoreSpec } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Result type for useLocalStore.
|
|
5
|
-
* Returns [state, actions, utilities] tuple.
|
|
6
|
-
*/
|
|
7
|
-
export type LocalStoreResult<TState extends StateBase, TActions extends ActionsBase> = readonly [
|
|
8
|
-
Readonly<TState>,
|
|
9
|
-
TActions,
|
|
10
|
-
Pick<StoreInstance<TState, TActions>, "dirty" | "reset">
|
|
11
|
-
];
|
|
12
|
-
/**
|
|
13
|
-
* Create a component-local store instance.
|
|
14
|
-
*
|
|
15
|
-
* The store is created when the component mounts and disposed when it unmounts.
|
|
16
|
-
* Each component instance gets its own isolated store.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```tsx
|
|
20
|
-
* const formSpec = store({
|
|
21
|
-
* name: "form",
|
|
22
|
-
* state: { name: "", email: "" },
|
|
23
|
-
* setup({ state }) {
|
|
24
|
-
* return {
|
|
25
|
-
* setName: (name: string) => { state.name = name; },
|
|
26
|
-
* setEmail: (email: string) => { state.email = email; },
|
|
27
|
-
* };
|
|
28
|
-
* },
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* function ContactForm() {
|
|
32
|
-
* const form = useLocalStore(formSpec);
|
|
33
|
-
* // Each ContactForm instance has its own form state
|
|
34
|
-
* return (
|
|
35
|
-
* <input
|
|
36
|
-
* value={form.state.name}
|
|
37
|
-
* onChange={(e) => form.actions.setName(e.target.value)}
|
|
38
|
-
* />
|
|
39
|
-
* );
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* @param spec - Store specification (must not have dependencies)
|
|
44
|
-
* @returns Store instance scoped to this component
|
|
45
|
-
* @throws Error if the store has dependencies on other stores
|
|
46
|
-
*/
|
|
47
|
-
export declare function useLocalStore<TState extends StateBase, TActions extends ActionsBase>(spec: StoreSpec<TState, TActions>): LocalStoreResult<TState, TActions>;
|
|
48
|
-
//# sourceMappingURL=useLocalStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalStore.d.ts","sourceRoot":"","sources":["../../src/react/useLocalStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EACL,WAAW,EACX,SAAS,EAET,aAAa,EACb,SAAS,EACV,MAAM,UAAU,CAAC;AAIlB;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAC1B,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,IAC1B,SAAS;IACX,QAAQ,CAAC,MAAM,CAAC;IAChB,QAAQ;IACR,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;CACzD,CAAC;AASF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAC3B,MAAM,SAAS,SAAS,EACxB,QAAQ,SAAS,WAAW,EAC5B,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CA8CvE"}
|