storion 0.20.0 → 0.20.1
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 +10 -0
- package/dist/async/abortable-guard.d.ts +25 -0
- package/dist/async/abortable-guard.d.ts.map +1 -0
- package/dist/async/abortable.d.ts +2 -6
- package/dist/async/abortable.d.ts.map +1 -1
- package/dist/async/index.js +271 -6
- package/dist/async/safe.d.ts.map +1 -1
- package/dist/{async-D0oaIaAZ.js → async-BwwGEvA0.js} +1 -1
- package/dist/{effect-YVnKUiyL.js → effect-BK2j3cpd.js} +36 -298
- package/dist/{index-BWTxMzzX.js → index-CMDQDIUy.js} +1 -1
- package/dist/network/index.js +2 -2
- package/dist/react/index.js +13 -6
- package/dist/react/useStore.d.ts.map +1 -1
- package/dist/storion.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.20.1] - 2025-12-31
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Fixed circular dependency warnings in async module (Metro/Expo). Extracted `isAbortable` and `abortableSymbol` to separate `abortable-guard.ts` file, and changed `toPromise` import to source from `utils.ts` directly instead of `async.ts`.
|
|
15
|
+
|
|
16
|
+
- Fixed Hot Module Replacement (HMR) causing "store disposed" errors with `scoped()` stores. Both `normalStrategy` and `strictStrategy` now use deferred disposal (50ms and 100ms respectively) to allow HMR bundle loading to complete before disposal fires. Previously, `normalStrategy` disposed immediately on cleanup, which raced with Metro's async module reloading.
|
|
17
|
+
|
|
18
|
+
## [0.20.0] - 2025-12-30
|
|
19
|
+
|
|
10
20
|
## [0.19.0] - 2025-12-30
|
|
11
21
|
|
|
12
22
|
### Added
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abortable type guard and symbol.
|
|
3
|
+
*
|
|
4
|
+
* Extracted to a separate file to avoid circular dependencies
|
|
5
|
+
* between safe.ts and abortable.ts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Symbol used to identify Abortable functions.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const abortableSymbol: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a value is an Abortable function.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* if (isAbortable(fn)) {
|
|
18
|
+
* fn.withSignal(signal, ...args);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function isAbortable(fn: unknown): fn is {
|
|
23
|
+
withSignal: Function;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=abortable-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortable-guard.d.ts","sourceRoot":"","sources":["../../src/async/abortable-guard.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;GAGG;AACH,eAAO,MAAM,eAAe,eAAkC,CAAC;AAM/D;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI;IAAE,UAAU,EAAE,QAAQ,CAAA;CAAE,CAMvE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SafeFnWithUtils } from './safe';
|
|
2
|
+
import { abortableSymbol, isAbortable } from './abortable-guard';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export { isAbortable };
|
|
4
5
|
export type AbortableStatus = "running" | "success" | "error" | "paused" | "waiting" | "aborted";
|
|
5
6
|
/**
|
|
6
7
|
* Send function type.
|
|
@@ -236,10 +237,6 @@ export interface Abortable<TArgs extends any[], TResult, TYield extends void | o
|
|
|
236
237
|
/** Type brand for discrimination */
|
|
237
238
|
readonly [abortableSymbol]: true;
|
|
238
239
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Check if a value is an Abortable.
|
|
241
|
-
*/
|
|
242
|
-
export declare function isAbortable<TArgs extends any[], TResult, TYield extends void | object = void>(fn: unknown): fn is Abortable<TArgs, TResult, TYield>;
|
|
243
240
|
/**
|
|
244
241
|
* Error thrown when abortable is aborted.
|
|
245
242
|
*/
|
|
@@ -291,5 +288,4 @@ export declare class AbortableAbortedError extends Error {
|
|
|
291
288
|
* ```
|
|
292
289
|
*/
|
|
293
290
|
export declare function abortable<const TArgs extends any[], TResult, TYield extends void | object = void>(fn: AbortableFn<TArgs, TResult, TYield>): Abortable<TArgs, TResult, TYield>;
|
|
294
|
-
export {};
|
|
295
291
|
//# sourceMappingURL=abortable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../src/async/abortable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../src/async/abortable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,CAAC;AAMvB,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,SAAS,GACT,OAAO,GACP,QAAQ,GACR,SAAS,GACT,SAAS,CAAC;AAMd;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,IAC3D,IAAI,SAAS,MAAM,GACf,MAAM,IAAI,GACV,CAAC,IAAI,SAAS,MAAM,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,C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AAQ,SAAS,GAAG,EAAE,GAAG,KAAK,EAC9B,SAAS,SAAS,IAAI,GAAG,MAAM,GAAG,MAAM,KACrC,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAEhD,oCAAoC;IACpC,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC;CAClC;AAOD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,2BAA2B;gBAE5B,OAAO,SAA0B;CAG9C;AAyXD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,SAAS,CACvB,KAAK,CAAC,KAAK,SAAS,GAAG,EAAE,EACzB,OAAO,EACP,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,EACnC,EAAE,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAmD5E"}
|
package/dist/async/index.js
CHANGED
|
@@ -1,6 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { a, b, c } from "../async-BwwGEvA0.js";
|
|
5
|
+
import { a as abortableSymbol, c as createSafe, i as isAbortable, r as retryStrategy, d as dev } from "../effect-BK2j3cpd.js";
|
|
6
|
+
import { b as b2, A, g, t } from "../effect-BK2j3cpd.js";
|
|
7
|
+
class AbortableAbortedError extends Error {
|
|
8
|
+
constructor(message = "Abortable was aborted") {
|
|
9
|
+
super(message);
|
|
10
|
+
__publicField(this, "name", "AbortableAbortedError");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function createAbortableContext(controller, pauseState, takeState, setStatus) {
|
|
14
|
+
const signal = controller.signal;
|
|
15
|
+
const checkPauseAndAbort = async () => {
|
|
16
|
+
if (signal.aborted) {
|
|
17
|
+
throw new AbortableAbortedError();
|
|
18
|
+
}
|
|
19
|
+
if (pauseState.isPaused) {
|
|
20
|
+
setStatus("paused");
|
|
21
|
+
await new Promise((resolve) => {
|
|
22
|
+
pauseState.resumeResolve = resolve;
|
|
23
|
+
});
|
|
24
|
+
pauseState.resumeResolve = null;
|
|
25
|
+
setStatus("running");
|
|
26
|
+
}
|
|
27
|
+
if (signal.aborted) {
|
|
28
|
+
throw new AbortableAbortedError();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const afterCheck = async (value) => {
|
|
32
|
+
await checkPauseAndAbort();
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
const join = (resultOrResults) => {
|
|
36
|
+
if (signal.aborted) {
|
|
37
|
+
return Promise.reject(new AbortableAbortedError());
|
|
38
|
+
}
|
|
39
|
+
const isArray = Array.isArray(resultOrResults);
|
|
40
|
+
const results = isArray ? resultOrResults : [resultOrResults];
|
|
41
|
+
const abortAll = () => {
|
|
42
|
+
for (const result of results) {
|
|
43
|
+
result.abort();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
signal.addEventListener("abort", abortAll, { once: true });
|
|
47
|
+
const promise = Promise.all(results).then(async (values) => {
|
|
48
|
+
signal.removeEventListener("abort", abortAll);
|
|
49
|
+
await checkPauseAndAbort();
|
|
50
|
+
return isArray ? values : values[0];
|
|
51
|
+
}).catch(async (error) => {
|
|
52
|
+
signal.removeEventListener("abort", abortAll);
|
|
53
|
+
abortAll();
|
|
54
|
+
if (signal.aborted) {
|
|
55
|
+
throw new AbortableAbortedError();
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
});
|
|
59
|
+
return promise;
|
|
60
|
+
};
|
|
61
|
+
const baseSafe = createSafe(
|
|
62
|
+
() => signal,
|
|
63
|
+
() => signal.aborted
|
|
64
|
+
);
|
|
65
|
+
const safeFn = async (fnOrPromise, ...args) => {
|
|
66
|
+
if (isAbortable(fnOrPromise)) {
|
|
67
|
+
const abortableResult = fnOrPromise.withSignal(signal, ...args);
|
|
68
|
+
return join(abortableResult);
|
|
69
|
+
}
|
|
70
|
+
const result = await baseSafe(fnOrPromise, ...args);
|
|
71
|
+
await checkPauseAndAbort();
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
const safe = Object.assign(safeFn, {
|
|
75
|
+
all: baseSafe.all,
|
|
76
|
+
race: baseSafe.race,
|
|
77
|
+
settled: baseSafe.settled,
|
|
78
|
+
any: baseSafe.any,
|
|
79
|
+
callback: baseSafe.callback,
|
|
80
|
+
delay: baseSafe.delay
|
|
81
|
+
});
|
|
82
|
+
const take = (key) => {
|
|
83
|
+
const takeKey = String(key ?? "__checkpoint__");
|
|
84
|
+
if (signal.aborted) {
|
|
85
|
+
return Promise.reject(new AbortableAbortedError());
|
|
86
|
+
}
|
|
87
|
+
const existing = takeState.pendingTakes.get(takeKey);
|
|
88
|
+
if (existing) {
|
|
89
|
+
return existing.promise.then(afterCheck);
|
|
90
|
+
}
|
|
91
|
+
let resolve;
|
|
92
|
+
let reject;
|
|
93
|
+
const promise = new Promise((res, rej) => {
|
|
94
|
+
resolve = res;
|
|
95
|
+
reject = rej;
|
|
96
|
+
});
|
|
97
|
+
takeState.pendingTakes.set(takeKey, {
|
|
98
|
+
resolve,
|
|
99
|
+
reject,
|
|
100
|
+
promise
|
|
101
|
+
});
|
|
102
|
+
setStatus("waiting");
|
|
103
|
+
return promise.then(afterCheck);
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
signal,
|
|
107
|
+
safe,
|
|
108
|
+
take,
|
|
109
|
+
join,
|
|
110
|
+
aborted: () => signal.aborted,
|
|
111
|
+
abort: () => {
|
|
112
|
+
if (signal.aborted) return false;
|
|
113
|
+
controller.abort();
|
|
114
|
+
return true;
|
|
115
|
+
},
|
|
116
|
+
checkpoint: checkPauseAndAbort
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createSend(takeState, setStatus) {
|
|
120
|
+
return (key, value) => {
|
|
121
|
+
const takeKey = String(key ?? "__checkpoint__");
|
|
122
|
+
const pending = takeState.pendingTakes.get(takeKey);
|
|
123
|
+
if (pending) {
|
|
124
|
+
pending.resolve(value);
|
|
125
|
+
takeState.pendingTakes.delete(takeKey);
|
|
126
|
+
setStatus("running");
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function executeAbortable(fn, args, parentSignal) {
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
if (parentSignal) {
|
|
133
|
+
if (parentSignal.aborted) {
|
|
134
|
+
controller.abort();
|
|
135
|
+
} else {
|
|
136
|
+
const onParentAbort = () => controller.abort();
|
|
137
|
+
parentSignal.addEventListener("abort", onParentAbort, { once: true });
|
|
138
|
+
controller.signal.addEventListener(
|
|
139
|
+
"abort",
|
|
140
|
+
() => parentSignal.removeEventListener("abort", onParentAbort),
|
|
141
|
+
{ once: true }
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let status = "running";
|
|
146
|
+
let resultValue;
|
|
147
|
+
let errorValue;
|
|
148
|
+
const pauseState = {
|
|
149
|
+
isPaused: false,
|
|
150
|
+
resumeResolve: null
|
|
151
|
+
};
|
|
152
|
+
const takeState = {
|
|
153
|
+
pendingTakes: /* @__PURE__ */ new Map()
|
|
154
|
+
};
|
|
155
|
+
const setStatus = (newStatus) => {
|
|
156
|
+
if (!["success", "error", "aborted"].includes(status)) {
|
|
157
|
+
status = newStatus;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const ctx = createAbortableContext(
|
|
161
|
+
controller,
|
|
162
|
+
pauseState,
|
|
163
|
+
takeState,
|
|
164
|
+
setStatus
|
|
165
|
+
);
|
|
166
|
+
const wrappedFn = async () => {
|
|
167
|
+
try {
|
|
168
|
+
if (controller.signal.aborted) {
|
|
169
|
+
throw new AbortableAbortedError();
|
|
170
|
+
}
|
|
171
|
+
const result = await fn(ctx, ...args);
|
|
172
|
+
return result;
|
|
173
|
+
} catch (e) {
|
|
174
|
+
if (controller.signal.aborted) {
|
|
175
|
+
throw new AbortableAbortedError();
|
|
176
|
+
}
|
|
177
|
+
throw e;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const promise = wrappedFn().then((result) => {
|
|
181
|
+
status = "success";
|
|
182
|
+
resultValue = result;
|
|
183
|
+
return result;
|
|
184
|
+
}).catch((error) => {
|
|
185
|
+
if (error instanceof AbortableAbortedError || controller.signal.aborted) {
|
|
186
|
+
status = "aborted";
|
|
187
|
+
errorValue = error instanceof Error ? error : new AbortableAbortedError();
|
|
188
|
+
} else {
|
|
189
|
+
status = "error";
|
|
190
|
+
errorValue = error instanceof Error ? error : new Error(String(error));
|
|
191
|
+
}
|
|
192
|
+
throw errorValue;
|
|
193
|
+
});
|
|
194
|
+
const send = createSend(takeState, setStatus);
|
|
195
|
+
return Object.assign(promise, {
|
|
196
|
+
send,
|
|
197
|
+
// Status checks
|
|
198
|
+
failed: () => status === "error",
|
|
199
|
+
completed: () => ["success", "error", "aborted"].includes(status),
|
|
200
|
+
running: () => status === "running",
|
|
201
|
+
succeeded: () => status === "success",
|
|
202
|
+
paused: () => status === "paused",
|
|
203
|
+
waiting: () => status === "waiting",
|
|
204
|
+
aborted: () => status === "aborted",
|
|
205
|
+
status: () => status,
|
|
206
|
+
// Result access
|
|
207
|
+
result: () => resultValue,
|
|
208
|
+
error: () => errorValue,
|
|
209
|
+
// Control methods
|
|
210
|
+
pause: () => {
|
|
211
|
+
if (pauseState.isPaused || ["success", "error", "aborted"].includes(status)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
pauseState.isPaused = true;
|
|
215
|
+
status = "paused";
|
|
216
|
+
return true;
|
|
217
|
+
},
|
|
218
|
+
resume: () => {
|
|
219
|
+
if (!pauseState.isPaused) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
pauseState.isPaused = false;
|
|
223
|
+
status = "running";
|
|
224
|
+
if (pauseState.resumeResolve) {
|
|
225
|
+
pauseState.resumeResolve();
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
},
|
|
229
|
+
abort: () => {
|
|
230
|
+
if (controller.signal.aborted || ["success", "error"].includes(status)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
status = "aborted";
|
|
234
|
+
controller.abort();
|
|
235
|
+
const abortError = new AbortableAbortedError();
|
|
236
|
+
for (const [, pending] of takeState.pendingTakes) {
|
|
237
|
+
pending.reject(abortError);
|
|
238
|
+
}
|
|
239
|
+
takeState.pendingTakes.clear();
|
|
240
|
+
if (pauseState.resumeResolve) {
|
|
241
|
+
pauseState.resumeResolve();
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function abortable(fn) {
|
|
248
|
+
const wrapper = (...args) => {
|
|
249
|
+
return executeAbortable(fn, args);
|
|
250
|
+
};
|
|
251
|
+
wrapper.withSignal = (signal, ...args) => {
|
|
252
|
+
return executeAbortable(fn, args, signal);
|
|
253
|
+
};
|
|
254
|
+
wrapper.use = (wrapperFn) => {
|
|
255
|
+
const wrappedHandler = wrapperFn(fn);
|
|
256
|
+
return abortable(wrappedHandler);
|
|
257
|
+
};
|
|
258
|
+
wrapper.as = () => {
|
|
259
|
+
return wrapper;
|
|
260
|
+
};
|
|
261
|
+
Object.defineProperty(wrapper, abortableSymbol, {
|
|
262
|
+
value: true,
|
|
263
|
+
writable: false,
|
|
264
|
+
enumerable: false,
|
|
265
|
+
configurable: false
|
|
266
|
+
});
|
|
267
|
+
return wrapper;
|
|
268
|
+
}
|
|
4
269
|
function retry(retriesOrStrategyOrOptions) {
|
|
5
270
|
const options = typeof retriesOrStrategyOrOptions === "number" ? { retries: retriesOrStrategyOrOptions } : typeof retriesOrStrategyOrOptions === "string" ? { delay: retriesOrStrategyOrOptions } : retriesOrStrategyOrOptions ?? {};
|
|
6
271
|
const retries = options.retries ?? 3;
|
|
@@ -284,18 +549,18 @@ function observe(onStart) {
|
|
|
284
549
|
export {
|
|
285
550
|
b2 as AsyncAggregateError,
|
|
286
551
|
A as AsyncNotReadyError,
|
|
287
|
-
|
|
552
|
+
abortable,
|
|
288
553
|
a as async,
|
|
289
554
|
b as asyncState,
|
|
290
555
|
c as asyncStateFrom,
|
|
291
556
|
cache,
|
|
292
557
|
catchError,
|
|
293
558
|
circuitBreaker,
|
|
294
|
-
|
|
559
|
+
createSafe,
|
|
295
560
|
debounce,
|
|
296
561
|
fallback,
|
|
297
562
|
g as getPendingPromise,
|
|
298
|
-
|
|
563
|
+
isAbortable,
|
|
299
564
|
logging,
|
|
300
565
|
map,
|
|
301
566
|
observe,
|
package/dist/async/safe.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../src/async/safe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../src/async/safe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAO7C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAAC,CAO3E;AA6CD;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,MAAM,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,GACV,OAAO,CAAC,CAAC,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G,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CAChE;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,sCAAsC;IACtC,GAAG,EAAE,OAAO,CAAC;IACb,2CAA2C;IAC3C,IAAI,EAAE,QAAQ,CAAC;IACf,wDAAwD;IACxD,OAAO,EAAE,WAAW,CAAC;IACrB,qCAAqC;IACrC,GAAG,EAAE,OAAO,CAAC;IACb,qDAAqD;IACrD,QAAQ,EAAE,YAAY,CAAC;IACvB,mDAAmD;IACnD,KAAK,EAAE,SAAS,CAAC;CAClB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,WAAW,GAAG,SAAS,EACxC,WAAW,EAAE,MAAM,OAAO,GACzB,eAAe,CA4NjB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as stateToJSON, c as createSafe, e as isSpec, k as storeTuple, B as SetupPhaseError, u as untrack, J as pendingPromises, K as createCancellablePromise, M as createAbortError, N as promiseTry, i as isAbortable, s as store, g as getPendingPromise, A as AsyncNotReadyError, O as getData, b as AsyncAggregateError, Q as isAsyncState, R as toPromiseWithState, T as isAsyncOrPromise, q as effect, f as AsyncFunctionError, U as state, V as invoke, W as delay } from "./effect-
|
|
1
|
+
import { G as stateToJSON, c as createSafe, e as isSpec, k as storeTuple, B as SetupPhaseError, u as untrack, J as pendingPromises, K as createCancellablePromise, M as createAbortError, N as promiseTry, i as isAbortable, s as store, g as getPendingPromise, A as AsyncNotReadyError, O as getData, b as AsyncAggregateError, Q as isAsyncState, R as toPromiseWithState, T as isAsyncOrPromise, q as effect, f as AsyncFunctionError, U as state, V as invoke, W as delay } from "./effect-BK2j3cpd.js";
|
|
2
2
|
import { i as isPromiseLike } from "./isPromiseLike-bFkfHAbm.js";
|
|
3
3
|
function asyncState(mode, status, dataOrError, errorOrExtra, extra) {
|
|
4
4
|
let state2;
|
|
@@ -3066,268 +3066,6 @@ const abortableSymbol = Symbol.for("storion.abortable");
|
|
|
3066
3066
|
function isAbortable(fn) {
|
|
3067
3067
|
return typeof fn === "function" && abortableSymbol in fn && fn[abortableSymbol] === true;
|
|
3068
3068
|
}
|
|
3069
|
-
class AbortableAbortedError extends Error {
|
|
3070
|
-
constructor(message = "Abortable was aborted") {
|
|
3071
|
-
super(message);
|
|
3072
|
-
__publicField(this, "name", "AbortableAbortedError");
|
|
3073
|
-
}
|
|
3074
|
-
}
|
|
3075
|
-
function createAbortableContext(controller, pauseState, takeState, setStatus) {
|
|
3076
|
-
const signal = controller.signal;
|
|
3077
|
-
const checkPauseAndAbort = async () => {
|
|
3078
|
-
if (signal.aborted) {
|
|
3079
|
-
throw new AbortableAbortedError();
|
|
3080
|
-
}
|
|
3081
|
-
if (pauseState.isPaused) {
|
|
3082
|
-
setStatus("paused");
|
|
3083
|
-
await new Promise((resolve) => {
|
|
3084
|
-
pauseState.resumeResolve = resolve;
|
|
3085
|
-
});
|
|
3086
|
-
pauseState.resumeResolve = null;
|
|
3087
|
-
setStatus("running");
|
|
3088
|
-
}
|
|
3089
|
-
if (signal.aborted) {
|
|
3090
|
-
throw new AbortableAbortedError();
|
|
3091
|
-
}
|
|
3092
|
-
};
|
|
3093
|
-
const afterCheck = async (value) => {
|
|
3094
|
-
await checkPauseAndAbort();
|
|
3095
|
-
return value;
|
|
3096
|
-
};
|
|
3097
|
-
const join = (resultOrResults) => {
|
|
3098
|
-
if (signal.aborted) {
|
|
3099
|
-
return Promise.reject(new AbortableAbortedError());
|
|
3100
|
-
}
|
|
3101
|
-
const isArray2 = Array.isArray(resultOrResults);
|
|
3102
|
-
const results = isArray2 ? resultOrResults : [resultOrResults];
|
|
3103
|
-
const abortAll = () => {
|
|
3104
|
-
for (const result of results) {
|
|
3105
|
-
result.abort();
|
|
3106
|
-
}
|
|
3107
|
-
};
|
|
3108
|
-
signal.addEventListener("abort", abortAll, { once: true });
|
|
3109
|
-
const promise = Promise.all(results).then(async (values) => {
|
|
3110
|
-
signal.removeEventListener("abort", abortAll);
|
|
3111
|
-
await checkPauseAndAbort();
|
|
3112
|
-
return isArray2 ? values : values[0];
|
|
3113
|
-
}).catch(async (error) => {
|
|
3114
|
-
signal.removeEventListener("abort", abortAll);
|
|
3115
|
-
abortAll();
|
|
3116
|
-
if (signal.aborted) {
|
|
3117
|
-
throw new AbortableAbortedError();
|
|
3118
|
-
}
|
|
3119
|
-
throw error;
|
|
3120
|
-
});
|
|
3121
|
-
return promise;
|
|
3122
|
-
};
|
|
3123
|
-
const baseSafe = createSafe(
|
|
3124
|
-
() => signal,
|
|
3125
|
-
() => signal.aborted
|
|
3126
|
-
);
|
|
3127
|
-
const safeFn = async (fnOrPromise, ...args) => {
|
|
3128
|
-
if (isAbortable(fnOrPromise)) {
|
|
3129
|
-
const abortableResult = fnOrPromise.withSignal(signal, ...args);
|
|
3130
|
-
return join(abortableResult);
|
|
3131
|
-
}
|
|
3132
|
-
const result = await baseSafe(fnOrPromise, ...args);
|
|
3133
|
-
await checkPauseAndAbort();
|
|
3134
|
-
return result;
|
|
3135
|
-
};
|
|
3136
|
-
const safe = Object.assign(safeFn, {
|
|
3137
|
-
all: baseSafe.all,
|
|
3138
|
-
race: baseSafe.race,
|
|
3139
|
-
settled: baseSafe.settled,
|
|
3140
|
-
any: baseSafe.any,
|
|
3141
|
-
callback: baseSafe.callback,
|
|
3142
|
-
delay: baseSafe.delay
|
|
3143
|
-
});
|
|
3144
|
-
const take = (key) => {
|
|
3145
|
-
const takeKey = String(key ?? "__checkpoint__");
|
|
3146
|
-
if (signal.aborted) {
|
|
3147
|
-
return Promise.reject(new AbortableAbortedError());
|
|
3148
|
-
}
|
|
3149
|
-
const existing = takeState.pendingTakes.get(takeKey);
|
|
3150
|
-
if (existing) {
|
|
3151
|
-
return existing.promise.then(afterCheck);
|
|
3152
|
-
}
|
|
3153
|
-
let resolve;
|
|
3154
|
-
let reject;
|
|
3155
|
-
const promise = new Promise((res, rej) => {
|
|
3156
|
-
resolve = res;
|
|
3157
|
-
reject = rej;
|
|
3158
|
-
});
|
|
3159
|
-
takeState.pendingTakes.set(takeKey, {
|
|
3160
|
-
resolve,
|
|
3161
|
-
reject,
|
|
3162
|
-
promise
|
|
3163
|
-
});
|
|
3164
|
-
setStatus("waiting");
|
|
3165
|
-
return promise.then(afterCheck);
|
|
3166
|
-
};
|
|
3167
|
-
return {
|
|
3168
|
-
signal,
|
|
3169
|
-
safe,
|
|
3170
|
-
take,
|
|
3171
|
-
join,
|
|
3172
|
-
aborted: () => signal.aborted,
|
|
3173
|
-
abort: () => {
|
|
3174
|
-
if (signal.aborted) return false;
|
|
3175
|
-
controller.abort();
|
|
3176
|
-
return true;
|
|
3177
|
-
},
|
|
3178
|
-
checkpoint: checkPauseAndAbort
|
|
3179
|
-
};
|
|
3180
|
-
}
|
|
3181
|
-
function createSend(takeState, setStatus) {
|
|
3182
|
-
return (key, value) => {
|
|
3183
|
-
const takeKey = String(key ?? "__checkpoint__");
|
|
3184
|
-
const pending = takeState.pendingTakes.get(takeKey);
|
|
3185
|
-
if (pending) {
|
|
3186
|
-
pending.resolve(value);
|
|
3187
|
-
takeState.pendingTakes.delete(takeKey);
|
|
3188
|
-
setStatus("running");
|
|
3189
|
-
}
|
|
3190
|
-
};
|
|
3191
|
-
}
|
|
3192
|
-
function executeAbortable(fn, args, parentSignal) {
|
|
3193
|
-
const controller = new AbortController();
|
|
3194
|
-
if (parentSignal) {
|
|
3195
|
-
if (parentSignal.aborted) {
|
|
3196
|
-
controller.abort();
|
|
3197
|
-
} else {
|
|
3198
|
-
const onParentAbort = () => controller.abort();
|
|
3199
|
-
parentSignal.addEventListener("abort", onParentAbort, { once: true });
|
|
3200
|
-
controller.signal.addEventListener(
|
|
3201
|
-
"abort",
|
|
3202
|
-
() => parentSignal.removeEventListener("abort", onParentAbort),
|
|
3203
|
-
{ once: true }
|
|
3204
|
-
);
|
|
3205
|
-
}
|
|
3206
|
-
}
|
|
3207
|
-
let status = "running";
|
|
3208
|
-
let resultValue;
|
|
3209
|
-
let errorValue;
|
|
3210
|
-
const pauseState = {
|
|
3211
|
-
isPaused: false,
|
|
3212
|
-
resumeResolve: null
|
|
3213
|
-
};
|
|
3214
|
-
const takeState = {
|
|
3215
|
-
pendingTakes: /* @__PURE__ */ new Map()
|
|
3216
|
-
};
|
|
3217
|
-
const setStatus = (newStatus) => {
|
|
3218
|
-
if (!["success", "error", "aborted"].includes(status)) {
|
|
3219
|
-
status = newStatus;
|
|
3220
|
-
}
|
|
3221
|
-
};
|
|
3222
|
-
const ctx = createAbortableContext(
|
|
3223
|
-
controller,
|
|
3224
|
-
pauseState,
|
|
3225
|
-
takeState,
|
|
3226
|
-
setStatus
|
|
3227
|
-
);
|
|
3228
|
-
const wrappedFn = async () => {
|
|
3229
|
-
try {
|
|
3230
|
-
if (controller.signal.aborted) {
|
|
3231
|
-
throw new AbortableAbortedError();
|
|
3232
|
-
}
|
|
3233
|
-
const result = await fn(ctx, ...args);
|
|
3234
|
-
return result;
|
|
3235
|
-
} catch (e) {
|
|
3236
|
-
if (controller.signal.aborted) {
|
|
3237
|
-
throw new AbortableAbortedError();
|
|
3238
|
-
}
|
|
3239
|
-
throw e;
|
|
3240
|
-
}
|
|
3241
|
-
};
|
|
3242
|
-
const promise = wrappedFn().then((result) => {
|
|
3243
|
-
status = "success";
|
|
3244
|
-
resultValue = result;
|
|
3245
|
-
return result;
|
|
3246
|
-
}).catch((error) => {
|
|
3247
|
-
if (error instanceof AbortableAbortedError || controller.signal.aborted) {
|
|
3248
|
-
status = "aborted";
|
|
3249
|
-
errorValue = error instanceof Error ? error : new AbortableAbortedError();
|
|
3250
|
-
} else {
|
|
3251
|
-
status = "error";
|
|
3252
|
-
errorValue = error instanceof Error ? error : new Error(String(error));
|
|
3253
|
-
}
|
|
3254
|
-
throw errorValue;
|
|
3255
|
-
});
|
|
3256
|
-
const send = createSend(takeState, setStatus);
|
|
3257
|
-
return Object.assign(promise, {
|
|
3258
|
-
send,
|
|
3259
|
-
// Status checks
|
|
3260
|
-
failed: () => status === "error",
|
|
3261
|
-
completed: () => ["success", "error", "aborted"].includes(status),
|
|
3262
|
-
running: () => status === "running",
|
|
3263
|
-
succeeded: () => status === "success",
|
|
3264
|
-
paused: () => status === "paused",
|
|
3265
|
-
waiting: () => status === "waiting",
|
|
3266
|
-
aborted: () => status === "aborted",
|
|
3267
|
-
status: () => status,
|
|
3268
|
-
// Result access
|
|
3269
|
-
result: () => resultValue,
|
|
3270
|
-
error: () => errorValue,
|
|
3271
|
-
// Control methods
|
|
3272
|
-
pause: () => {
|
|
3273
|
-
if (pauseState.isPaused || ["success", "error", "aborted"].includes(status)) {
|
|
3274
|
-
return false;
|
|
3275
|
-
}
|
|
3276
|
-
pauseState.isPaused = true;
|
|
3277
|
-
status = "paused";
|
|
3278
|
-
return true;
|
|
3279
|
-
},
|
|
3280
|
-
resume: () => {
|
|
3281
|
-
if (!pauseState.isPaused) {
|
|
3282
|
-
return false;
|
|
3283
|
-
}
|
|
3284
|
-
pauseState.isPaused = false;
|
|
3285
|
-
status = "running";
|
|
3286
|
-
if (pauseState.resumeResolve) {
|
|
3287
|
-
pauseState.resumeResolve();
|
|
3288
|
-
}
|
|
3289
|
-
return true;
|
|
3290
|
-
},
|
|
3291
|
-
abort: () => {
|
|
3292
|
-
if (controller.signal.aborted || ["success", "error"].includes(status)) {
|
|
3293
|
-
return false;
|
|
3294
|
-
}
|
|
3295
|
-
status = "aborted";
|
|
3296
|
-
controller.abort();
|
|
3297
|
-
const abortError = new AbortableAbortedError();
|
|
3298
|
-
for (const [, pending] of takeState.pendingTakes) {
|
|
3299
|
-
pending.reject(abortError);
|
|
3300
|
-
}
|
|
3301
|
-
takeState.pendingTakes.clear();
|
|
3302
|
-
if (pauseState.resumeResolve) {
|
|
3303
|
-
pauseState.resumeResolve();
|
|
3304
|
-
}
|
|
3305
|
-
return true;
|
|
3306
|
-
}
|
|
3307
|
-
});
|
|
3308
|
-
}
|
|
3309
|
-
function abortable(fn) {
|
|
3310
|
-
const wrapper = (...args) => {
|
|
3311
|
-
return executeAbortable(fn, args);
|
|
3312
|
-
};
|
|
3313
|
-
wrapper.withSignal = (signal, ...args) => {
|
|
3314
|
-
return executeAbortable(fn, args, signal);
|
|
3315
|
-
};
|
|
3316
|
-
wrapper.use = (wrapperFn) => {
|
|
3317
|
-
const wrappedHandler = wrapperFn(fn);
|
|
3318
|
-
return abortable(wrappedHandler);
|
|
3319
|
-
};
|
|
3320
|
-
wrapper.as = () => {
|
|
3321
|
-
return wrapper;
|
|
3322
|
-
};
|
|
3323
|
-
Object.defineProperty(wrapper, abortableSymbol, {
|
|
3324
|
-
value: true,
|
|
3325
|
-
writable: false,
|
|
3326
|
-
enumerable: false,
|
|
3327
|
-
configurable: false
|
|
3328
|
-
});
|
|
3329
|
-
return wrapper;
|
|
3330
|
-
}
|
|
3331
3069
|
function createAbortError(message = "Aborted") {
|
|
3332
3070
|
if (typeof DOMException !== "undefined") {
|
|
3333
3071
|
return new DOMException(message, "AbortError");
|
|
@@ -3508,41 +3246,6 @@ function toPromise(value) {
|
|
|
3508
3246
|
}
|
|
3509
3247
|
return Promise.resolve(value);
|
|
3510
3248
|
}
|
|
3511
|
-
const retryStrategy = {
|
|
3512
|
-
/** Exponential backoff: 1s, 2s, 4s, 8s... (max 30s) */
|
|
3513
|
-
backoff: (attempt) => Math.min(1e3 * 2 ** attempt, 3e4),
|
|
3514
|
-
/** Linear: 1s, 2s, 3s, 4s... (max 30s) */
|
|
3515
|
-
linear: (attempt) => Math.min(1e3 * (attempt + 1), 3e4),
|
|
3516
|
-
/** Fixed 1 second delay */
|
|
3517
|
-
fixed: () => 1e3,
|
|
3518
|
-
/** Fibonacci: 1s, 1s, 2s, 3s, 5s, 8s... (max 30s) */
|
|
3519
|
-
fibonacci: (attempt) => {
|
|
3520
|
-
const fib = [1, 1, 2, 3, 5, 8, 13, 21, 30];
|
|
3521
|
-
return Math.min(fib[attempt] ?? 30, 30) * 1e3;
|
|
3522
|
-
},
|
|
3523
|
-
/** Immediate retry (no delay) */
|
|
3524
|
-
immediate: () => 0,
|
|
3525
|
-
/** Add jitter (±30%) to any strategy */
|
|
3526
|
-
withJitter: (strategy) => (attempt) => {
|
|
3527
|
-
const base = strategy(attempt);
|
|
3528
|
-
const jitter = base * 0.3 * (Math.random() * 2 - 1);
|
|
3529
|
-
return Math.max(0, Math.round(base + jitter));
|
|
3530
|
-
}
|
|
3531
|
-
};
|
|
3532
|
-
class AsyncNotReadyError extends Error {
|
|
3533
|
-
constructor(message, status) {
|
|
3534
|
-
super(message);
|
|
3535
|
-
this.status = status;
|
|
3536
|
-
this.name = "AsyncNotReadyError";
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
class AsyncAggregateError extends Error {
|
|
3540
|
-
constructor(message, errors2) {
|
|
3541
|
-
super(message);
|
|
3542
|
-
this.errors = errors2;
|
|
3543
|
-
this.name = "AsyncAggregateError";
|
|
3544
|
-
}
|
|
3545
|
-
}
|
|
3546
3249
|
function isPromiseLike(value) {
|
|
3547
3250
|
return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
3548
3251
|
}
|
|
@@ -3709,6 +3412,41 @@ function createSafe(getSignal, isCancelled) {
|
|
|
3709
3412
|
delay: delay2
|
|
3710
3413
|
});
|
|
3711
3414
|
}
|
|
3415
|
+
const retryStrategy = {
|
|
3416
|
+
/** Exponential backoff: 1s, 2s, 4s, 8s... (max 30s) */
|
|
3417
|
+
backoff: (attempt) => Math.min(1e3 * 2 ** attempt, 3e4),
|
|
3418
|
+
/** Linear: 1s, 2s, 3s, 4s... (max 30s) */
|
|
3419
|
+
linear: (attempt) => Math.min(1e3 * (attempt + 1), 3e4),
|
|
3420
|
+
/** Fixed 1 second delay */
|
|
3421
|
+
fixed: () => 1e3,
|
|
3422
|
+
/** Fibonacci: 1s, 1s, 2s, 3s, 5s, 8s... (max 30s) */
|
|
3423
|
+
fibonacci: (attempt) => {
|
|
3424
|
+
const fib = [1, 1, 2, 3, 5, 8, 13, 21, 30];
|
|
3425
|
+
return Math.min(fib[attempt] ?? 30, 30) * 1e3;
|
|
3426
|
+
},
|
|
3427
|
+
/** Immediate retry (no delay) */
|
|
3428
|
+
immediate: () => 0,
|
|
3429
|
+
/** Add jitter (±30%) to any strategy */
|
|
3430
|
+
withJitter: (strategy) => (attempt) => {
|
|
3431
|
+
const base = strategy(attempt);
|
|
3432
|
+
const jitter = base * 0.3 * (Math.random() * 2 - 1);
|
|
3433
|
+
return Math.max(0, Math.round(base + jitter));
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
class AsyncNotReadyError extends Error {
|
|
3437
|
+
constructor(message, status) {
|
|
3438
|
+
super(message);
|
|
3439
|
+
this.status = status;
|
|
3440
|
+
this.name = "AsyncNotReadyError";
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
class AsyncAggregateError extends Error {
|
|
3444
|
+
constructor(message, errors2) {
|
|
3445
|
+
super(message);
|
|
3446
|
+
this.errors = errors2;
|
|
3447
|
+
this.name = "AsyncAggregateError";
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3712
3450
|
function createEffectContext(nth, onRefresh) {
|
|
3713
3451
|
let cleanupEmitter = null;
|
|
3714
3452
|
let abortController = null;
|
|
@@ -4015,7 +3753,7 @@ export {
|
|
|
4015
3753
|
delay as W,
|
|
4016
3754
|
tryDispose as X,
|
|
4017
3755
|
unwrapFn as Y,
|
|
4018
|
-
|
|
3756
|
+
abortableSymbol as a,
|
|
4019
3757
|
AsyncAggregateError as b,
|
|
4020
3758
|
createSafe as c,
|
|
4021
3759
|
dev as d,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as tryDispose, e as isSpec, u as untrack, l as STORION_TYPE, o as batch, Y as unwrapFn, x as shallowEqual, m as resolveEquality } from "./effect-
|
|
1
|
+
import { X as tryDispose, e as isSpec, u as untrack, l as STORION_TYPE, o as batch, Y as unwrapFn, x as shallowEqual, m as resolveEquality } from "./effect-BK2j3cpd.js";
|
|
2
2
|
import { e as emitter } from "./emitter-Blea9fPg.js";
|
|
3
3
|
import "./meta-BW3y6_f6.js";
|
|
4
4
|
function createMetaQuery(entries) {
|
package/dist/network/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as async } from "../async-
|
|
1
|
+
import { a as async } from "../async-BwwGEvA0.js";
|
|
2
2
|
import { e as emitter } from "../emitter-Blea9fPg.js";
|
|
3
|
-
import { s as store } from "../effect-
|
|
3
|
+
import { s as store } from "../effect-BK2j3cpd.js";
|
|
4
4
|
const pingService = () => {
|
|
5
5
|
return {
|
|
6
6
|
ping: async () => {
|
package/dist/react/index.js
CHANGED
|
@@ -2,10 +2,10 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { memo, useRef, useMemo, createElement, createContext, useContext, StrictMode as StrictMode$1, useReducer, useLayoutEffect, useEffect, forwardRef, useState } from "react";
|
|
5
|
-
import { c as container, m as microtask } from "../index-
|
|
6
|
-
import { k, q, o, j, e, d, h, s, g, i, l, b, n, v, f, p, r, a, t, u, w } from "../index-
|
|
7
|
-
import { P as ProviderMissingError, e as isSpec, w as withHooks, f as AsyncFunctionError, h as tryStabilize, j as strictEqual, S as ScopedOutsideSelectorError, k as storeTuple, l as STORION_TYPE, m as resolveEquality, s as store } from "../effect-
|
|
8
|
-
import { E, H, I, L, D, B, C, z, o as o2, y, q as q2, v as v2, n as n2, p as p2, F, x, u as u2 } from "../effect-
|
|
5
|
+
import { c as container, m as microtask } from "../index-CMDQDIUy.js";
|
|
6
|
+
import { k, q, o, j, e, d, h, s, g, i, l, b, n, v, f, p, r, a, t, u, w } from "../index-CMDQDIUy.js";
|
|
7
|
+
import { P as ProviderMissingError, e as isSpec, w as withHooks, f as AsyncFunctionError, h as tryStabilize, j as strictEqual, d as dev, S as ScopedOutsideSelectorError, k as storeTuple, l as STORION_TYPE, m as resolveEquality, s as store } from "../effect-BK2j3cpd.js";
|
|
8
|
+
import { E, H, I, L, D, B, C, z, o as o2, y, q as q2, v as v2, n as n2, p as p2, F, x, u as u2 } from "../effect-BK2j3cpd.js";
|
|
9
9
|
import { e as emitter } from "../emitter-Blea9fPg.js";
|
|
10
10
|
import { i as isPromiseLike } from "../isPromiseLike-bFkfHAbm.js";
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -45,13 +45,20 @@ function useStrictMode() {
|
|
|
45
45
|
return useContext(context);
|
|
46
46
|
}
|
|
47
47
|
const useIsomorphicLayoutEffect = typeof window !== "undefined" && typeof useLayoutEffect === "function" ? useLayoutEffect : useEffect;
|
|
48
|
-
const
|
|
48
|
+
const HMR_SAFETY_DELAY = 50;
|
|
49
|
+
const normalStrategy = dev() ? (dispose, when) => {
|
|
50
|
+
if (when === "uncommit") {
|
|
51
|
+
const id = setTimeout(dispose, HMR_SAFETY_DELAY);
|
|
52
|
+
return () => clearTimeout(id);
|
|
53
|
+
}
|
|
54
|
+
} : (dispose, when) => {
|
|
49
55
|
if (when === "uncommit") {
|
|
50
56
|
dispose();
|
|
51
57
|
}
|
|
52
58
|
};
|
|
59
|
+
const STRICT_MODE_DISPOSE_DELAY = 100;
|
|
53
60
|
const strictStrategy = (dispose, _when) => {
|
|
54
|
-
const id = setTimeout(dispose,
|
|
61
|
+
const id = setTimeout(dispose, STRICT_MODE_DISPOSE_DELAY);
|
|
55
62
|
return () => clearTimeout(id);
|
|
56
63
|
};
|
|
57
64
|
let useStoreSelectorDepth = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../src/react/useStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAEL,KAAK,SA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M,EACpD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,cAAc,GACxB,YAAY,CAAC,CAAC,CAAC,CA0IjB;AAyJD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAE3D;;;;;;;;;;;;;;OAcG;IACH,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAEjC;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,MAAM,SAAS,SAAS,EAAE,QAAQ,SAAS,WAAW,EACzD,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,GAChC,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAElC;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,OAAO,SAAS,MAAM,EAAE,KAAK,SAAS,OAAO,EAAE,EAClD,QAAQ,EAAE,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,GAC7C,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CACxC;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,UAErB,CAAC"}
|
package/dist/storion.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f, E, H, I, L, D, P, l, B, C, z, o, y, q, v, n, p, F, x, s, j, u, w } from "./effect-
|
|
2
|
-
import { k, q as q2, o as o2, j as j2, c, e, d, h, s as s2, g, i, l as l2, b, n as n2, v as v2, f as f2, p as p2, r, a, t, u as u2, w as w2 } from "./index-
|
|
1
|
+
import { f, E, H, I, L, D, P, l, B, C, z, o, y, q, v, n, p, F, x, s, j, u, w } from "./effect-BK2j3cpd.js";
|
|
2
|
+
import { k, q as q2, o as o2, j as j2, c, e, d, h, s as s2, g, i, l as l2, b, n as n2, v as v2, f as f2, p as p2, r, a, t, u as u2, w as w2 } from "./index-CMDQDIUy.js";
|
|
3
3
|
import { m } from "./meta-BW3y6_f6.js";
|
|
4
4
|
import { e as e2 } from "./emitter-Blea9fPg.js";
|
|
5
5
|
export {
|