solid-js 2.0.0-experimental.13 → 2.0.0-experimental.14
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/dist/dev.cjs +78 -38
- package/dist/dev.js +88 -43
- package/dist/server.cjs +535 -0
- package/dist/server.js +441 -0
- package/dist/solid.cjs +78 -38
- package/dist/solid.js +88 -43
- package/package.json +4 -4
- package/types/client/component.d.ts +0 -1
- package/types/client/flow.d.ts +1 -5
- package/types/client/hydration.d.ts +5 -1
- package/types/index.d.ts +3 -4
- package/types/server/component.d.ts +62 -0
- package/types/server/core.d.ts +43 -0
- package/types/server/flow.d.ts +60 -0
- package/types/server/hydration.d.ts +21 -0
- package/types/server/index.d.ts +12 -1
- package/types/server/shared.d.ts +24 -0
- package/types/server/signals.d.ts +54 -0
- package/types/utilities.d.ts +0 -36
package/dist/server.js
CHANGED
|
@@ -1 +1,442 @@
|
|
|
1
|
+
import { getOwner, getNextChildId, createOwner, runWithOwner, isWrappable, NotReadyError, setContext, getContext, createRoot, flatten } from '@solidjs/signals';
|
|
2
|
+
export { $PROXY, $TRACK, NotReadyError, createRoot, flatten, getOwner, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot } from '@solidjs/signals';
|
|
1
3
|
|
|
4
|
+
const sharedConfig = {
|
|
5
|
+
getNextContextId() {
|
|
6
|
+
const o = getOwner();
|
|
7
|
+
if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
8
|
+
return getNextChildId(o);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let Observer = null;
|
|
13
|
+
function runWithObserver(comp, fn) {
|
|
14
|
+
const prev = Observer;
|
|
15
|
+
Observer = comp;
|
|
16
|
+
try {
|
|
17
|
+
return fn();
|
|
18
|
+
} finally {
|
|
19
|
+
Observer = prev;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getObserver() {
|
|
23
|
+
return Observer;
|
|
24
|
+
}
|
|
25
|
+
function createSignal(first, second, third) {
|
|
26
|
+
if (typeof first === "function") {
|
|
27
|
+
const memo = createMemo(p => {
|
|
28
|
+
let value = first(p ? p[0]() : second);
|
|
29
|
+
return [() => value, v => {
|
|
30
|
+
return value = typeof v === "function" ? v(value) : v;
|
|
31
|
+
}];
|
|
32
|
+
});
|
|
33
|
+
return [() => memo()[0](), v => memo()[1](v)];
|
|
34
|
+
}
|
|
35
|
+
return [() => first, v => {
|
|
36
|
+
return first = typeof v === "function" ? v(first) : v;
|
|
37
|
+
}];
|
|
38
|
+
}
|
|
39
|
+
function createMemo(compute, value, options) {
|
|
40
|
+
const ctx = sharedConfig.context;
|
|
41
|
+
const owner = createOwner();
|
|
42
|
+
const comp = {
|
|
43
|
+
owner,
|
|
44
|
+
value: value,
|
|
45
|
+
compute: compute,
|
|
46
|
+
error: undefined,
|
|
47
|
+
computed: false
|
|
48
|
+
};
|
|
49
|
+
function update() {
|
|
50
|
+
try {
|
|
51
|
+
comp.error = undefined;
|
|
52
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
53
|
+
comp.computed = true;
|
|
54
|
+
processResult(comp, result, owner, ctx);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
if (err instanceof NotReadyError) {
|
|
57
|
+
err.source?.then(() => update());
|
|
58
|
+
}
|
|
59
|
+
comp.error = err;
|
|
60
|
+
comp.computed = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!options?.lazy) {
|
|
64
|
+
update();
|
|
65
|
+
}
|
|
66
|
+
return () => {
|
|
67
|
+
if (!comp.computed) {
|
|
68
|
+
update();
|
|
69
|
+
}
|
|
70
|
+
if (comp.error) {
|
|
71
|
+
throw comp.error;
|
|
72
|
+
}
|
|
73
|
+
return comp.value;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function processResult(comp, result, owner, ctx) {
|
|
77
|
+
const id = owner.id;
|
|
78
|
+
const uninitialized = comp.value === undefined;
|
|
79
|
+
if (result instanceof Promise) {
|
|
80
|
+
result.then(v => {
|
|
81
|
+
result.s = 1;
|
|
82
|
+
result.v = comp.value = v;
|
|
83
|
+
comp.error = undefined;
|
|
84
|
+
});
|
|
85
|
+
if (ctx?.serialize && id) ctx.serialize(id, result);
|
|
86
|
+
if (uninitialized) {
|
|
87
|
+
comp.error = new NotReadyError(result);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const iterator = result?.[Symbol.asyncIterator];
|
|
92
|
+
if (typeof iterator === "function") {
|
|
93
|
+
const iter = iterator.call(result);
|
|
94
|
+
const promise = iter.next().then(v => {
|
|
95
|
+
promise.s = 1;
|
|
96
|
+
promise.v = comp.value = v.value;
|
|
97
|
+
comp.error = undefined;
|
|
98
|
+
});
|
|
99
|
+
if (ctx?.serialize && id) ctx.serialize(id, promise);
|
|
100
|
+
if (uninitialized) {
|
|
101
|
+
comp.error = new NotReadyError(promise);
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
comp.value = result;
|
|
106
|
+
}
|
|
107
|
+
function createEffect(compute, effect, value, options) {
|
|
108
|
+
const o = getOwner();
|
|
109
|
+
if (o?.id != null) getNextChildId(o);
|
|
110
|
+
}
|
|
111
|
+
function createRenderEffect(compute, effectFn, value, options) {
|
|
112
|
+
const owner = createOwner();
|
|
113
|
+
try {
|
|
114
|
+
const result = runWithOwner(owner, () => runWithObserver({
|
|
115
|
+
owner,
|
|
116
|
+
value: value,
|
|
117
|
+
compute: compute,
|
|
118
|
+
error: undefined,
|
|
119
|
+
computed: true
|
|
120
|
+
}, () => compute(value)));
|
|
121
|
+
effectFn(result, value);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function createTrackedEffect(compute, options) {
|
|
126
|
+
const o = getOwner();
|
|
127
|
+
if (o?.id != null) getNextChildId(o);
|
|
128
|
+
}
|
|
129
|
+
function createReaction(effectFn, options) {
|
|
130
|
+
return tracking => {
|
|
131
|
+
tracking();
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function createOptimistic(first, second, third) {
|
|
135
|
+
return createSignal(first, second);
|
|
136
|
+
}
|
|
137
|
+
function setProperty(state, property, value) {
|
|
138
|
+
if (state[property] === value) return;
|
|
139
|
+
if (value === undefined) {
|
|
140
|
+
delete state[property];
|
|
141
|
+
} else state[property] = value;
|
|
142
|
+
}
|
|
143
|
+
function createStore(state) {
|
|
144
|
+
function setStore(fn) {
|
|
145
|
+
fn(state);
|
|
146
|
+
}
|
|
147
|
+
return [state, setStore];
|
|
148
|
+
}
|
|
149
|
+
const createOptimisticStore = createStore;
|
|
150
|
+
function createProjection(fn, initialValue = {}) {
|
|
151
|
+
const [state] = createStore(initialValue);
|
|
152
|
+
fn(state);
|
|
153
|
+
return state;
|
|
154
|
+
}
|
|
155
|
+
function reconcile(value) {
|
|
156
|
+
return state => {
|
|
157
|
+
if (!isWrappable(state) || !isWrappable(value)) return value;
|
|
158
|
+
const targetKeys = Object.keys(value);
|
|
159
|
+
const previousKeys = Object.keys(state);
|
|
160
|
+
for (let i = 0, len = targetKeys.length; i < len; i++) {
|
|
161
|
+
const key = targetKeys[i];
|
|
162
|
+
setProperty(state, key, value[key]);
|
|
163
|
+
}
|
|
164
|
+
for (let i = 0, len = previousKeys.length; i < len; i++) {
|
|
165
|
+
if (value[previousKeys[i]] === undefined) setProperty(state, previousKeys[i], undefined);
|
|
166
|
+
}
|
|
167
|
+
return state;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function deep(store) {
|
|
171
|
+
return store;
|
|
172
|
+
}
|
|
173
|
+
function mapArray(list, mapFn, options = {}) {
|
|
174
|
+
const root = getOwner();
|
|
175
|
+
const id = getNextChildId(root);
|
|
176
|
+
return () => {
|
|
177
|
+
const items = list();
|
|
178
|
+
let s = [];
|
|
179
|
+
if (items && items.length) {
|
|
180
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
|
181
|
+
const o = createOwner({
|
|
182
|
+
id: id + i
|
|
183
|
+
});
|
|
184
|
+
s.push(runWithOwner(o, () => mapFn(() => items[i], () => i)));
|
|
185
|
+
}
|
|
186
|
+
} else if (options.fallback) s = [options.fallback()];
|
|
187
|
+
return s;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function repeat(count, mapFn, options = {}) {
|
|
191
|
+
const len = count();
|
|
192
|
+
const offset = options.from?.() || 0;
|
|
193
|
+
let s = [];
|
|
194
|
+
if (len) {
|
|
195
|
+
for (let i = 0; i < len; i++) s.push(mapFn(i + offset));
|
|
196
|
+
} else if (options.fallback) s = [options.fallback()];
|
|
197
|
+
return () => s;
|
|
198
|
+
}
|
|
199
|
+
const ErrorContext = {
|
|
200
|
+
id: Symbol("ErrorContext"),
|
|
201
|
+
defaultValue: null
|
|
202
|
+
};
|
|
203
|
+
function createErrorBoundary(fn, fallback) {
|
|
204
|
+
const owner = createOwner();
|
|
205
|
+
return runWithOwner(owner, () => {
|
|
206
|
+
let result;
|
|
207
|
+
setContext(ErrorContext, err => {
|
|
208
|
+
result = fallback(err, () => {});
|
|
209
|
+
});
|
|
210
|
+
try {
|
|
211
|
+
result = fn();
|
|
212
|
+
} catch (err) {
|
|
213
|
+
result = fallback(err, () => {});
|
|
214
|
+
}
|
|
215
|
+
return () => result;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function createLoadBoundary(fn, fallback) {
|
|
219
|
+
try {
|
|
220
|
+
const result = fn();
|
|
221
|
+
return () => result;
|
|
222
|
+
} catch (err) {
|
|
223
|
+
if (err instanceof NotReadyError) {
|
|
224
|
+
return () => fallback();
|
|
225
|
+
}
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function untrack(fn) {
|
|
230
|
+
return fn();
|
|
231
|
+
}
|
|
232
|
+
function flush() {}
|
|
233
|
+
function resolve(fn) {
|
|
234
|
+
throw new Error("resolve is not implemented on the server");
|
|
235
|
+
}
|
|
236
|
+
function isPending(fn, fallback) {
|
|
237
|
+
try {
|
|
238
|
+
fn();
|
|
239
|
+
return false;
|
|
240
|
+
} catch (err) {
|
|
241
|
+
if (err instanceof NotReadyError && arguments.length > 1) {
|
|
242
|
+
return fallback;
|
|
243
|
+
}
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function pending(fn) {
|
|
248
|
+
return fn();
|
|
249
|
+
}
|
|
250
|
+
function isRefreshing() {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
function refresh(fn) {
|
|
254
|
+
return fn();
|
|
255
|
+
}
|
|
256
|
+
function action(fn) {
|
|
257
|
+
return fn;
|
|
258
|
+
}
|
|
259
|
+
function onSettled(callback) {
|
|
260
|
+
const o = getOwner();
|
|
261
|
+
if (o?.id != null) getNextChildId(o);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const $DEVCOMP = Symbol("solid-dev-component");
|
|
265
|
+
function createContext(defaultValue, options) {
|
|
266
|
+
const id = Symbol(options && options.name || "");
|
|
267
|
+
function provider(props) {
|
|
268
|
+
return createRoot(() => {
|
|
269
|
+
setContext(provider, props.value);
|
|
270
|
+
return children(() => props.children);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
provider.id = id;
|
|
274
|
+
provider.defaultValue = defaultValue;
|
|
275
|
+
return provider;
|
|
276
|
+
}
|
|
277
|
+
function useContext(context) {
|
|
278
|
+
return getContext(context);
|
|
279
|
+
}
|
|
280
|
+
function children(fn) {
|
|
281
|
+
const childrenMemo = createMemo(fn);
|
|
282
|
+
const memo = createMemo(() => flatten(childrenMemo()));
|
|
283
|
+
memo.toArray = () => {
|
|
284
|
+
const c = memo();
|
|
285
|
+
return Array.isArray(c) ? c : c != null ? [c] : [];
|
|
286
|
+
};
|
|
287
|
+
return memo;
|
|
288
|
+
}
|
|
289
|
+
function ssrRunInScope(fn) {
|
|
290
|
+
if (Array.isArray(fn)) {
|
|
291
|
+
const o = createOwner();
|
|
292
|
+
return fn.map(f => runWithOwner.bind(null, o, f));
|
|
293
|
+
}
|
|
294
|
+
return runWithOwner.bind(null, createOwner(), fn);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function enableHydration() {}
|
|
298
|
+
function createComponent(Comp, props) {
|
|
299
|
+
return Comp(props || {});
|
|
300
|
+
}
|
|
301
|
+
function lazy(fn) {
|
|
302
|
+
let p;
|
|
303
|
+
let load = id => {
|
|
304
|
+
if (!p) {
|
|
305
|
+
p = fn();
|
|
306
|
+
p.then(mod => {
|
|
307
|
+
p.v = mod.default;
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return p;
|
|
311
|
+
};
|
|
312
|
+
const wrap = props => {
|
|
313
|
+
sharedConfig.getNextContextId();
|
|
314
|
+
load();
|
|
315
|
+
if (p.v) return p.v(props);
|
|
316
|
+
if (sharedConfig.context?.async) {
|
|
317
|
+
sharedConfig.context.block(p.then(() => {
|
|
318
|
+
p.s = "success";
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
throw new NotReadyError(p);
|
|
322
|
+
};
|
|
323
|
+
wrap.preload = load;
|
|
324
|
+
return wrap;
|
|
325
|
+
}
|
|
326
|
+
function createUniqueId() {
|
|
327
|
+
return sharedConfig.getNextContextId();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function For(props) {
|
|
331
|
+
const options = "fallback" in props ? {
|
|
332
|
+
keyed: props.keyed,
|
|
333
|
+
fallback: () => props.fallback
|
|
334
|
+
} : {
|
|
335
|
+
keyed: props.keyed
|
|
336
|
+
};
|
|
337
|
+
return createMemo(mapArray(() => props.each, props.children, options));
|
|
338
|
+
}
|
|
339
|
+
function Repeat(props) {
|
|
340
|
+
const options = "fallback" in props ? {
|
|
341
|
+
fallback: () => props.fallback
|
|
342
|
+
} : {};
|
|
343
|
+
options.from = () => props.from;
|
|
344
|
+
return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
|
|
345
|
+
}
|
|
346
|
+
function Show(props) {
|
|
347
|
+
const when = props.when;
|
|
348
|
+
if (when) {
|
|
349
|
+
const child = props.children;
|
|
350
|
+
if (typeof child === "function" && child.length > 0) {
|
|
351
|
+
return child(() => when);
|
|
352
|
+
}
|
|
353
|
+
return child;
|
|
354
|
+
}
|
|
355
|
+
return props.fallback;
|
|
356
|
+
}
|
|
357
|
+
function Switch(props) {
|
|
358
|
+
const chs = children(() => props.children);
|
|
359
|
+
const o = getOwner();
|
|
360
|
+
if (o) getNextChildId(o);
|
|
361
|
+
return createMemo(() => {
|
|
362
|
+
let conds = chs();
|
|
363
|
+
if (!Array.isArray(conds)) conds = [conds];
|
|
364
|
+
for (let i = 0; i < conds.length; i++) {
|
|
365
|
+
const w = conds[i].when;
|
|
366
|
+
if (w) {
|
|
367
|
+
const c = conds[i].children;
|
|
368
|
+
return typeof c === "function" && c.length > 0 ? c(() => w) : c;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return props.fallback;
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
function Match(props) {
|
|
375
|
+
return props;
|
|
376
|
+
}
|
|
377
|
+
function Errored(props) {
|
|
378
|
+
return createErrorBoundary(() => props.children, (err, reset) => {
|
|
379
|
+
const f = props.fallback;
|
|
380
|
+
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function ssrHandleError(err) {
|
|
385
|
+
if (err instanceof NotReadyError) {
|
|
386
|
+
return err.source;
|
|
387
|
+
}
|
|
388
|
+
const handler = getContext(ErrorContext);
|
|
389
|
+
if (handler) {
|
|
390
|
+
handler(err);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
throw err;
|
|
394
|
+
}
|
|
395
|
+
function Loading(props) {
|
|
396
|
+
const ctx = sharedConfig.context;
|
|
397
|
+
if (!ctx) {
|
|
398
|
+
return createLoadBoundary(() => props.children, () => props.fallback);
|
|
399
|
+
}
|
|
400
|
+
const o = createOwner();
|
|
401
|
+
const id = o.id;
|
|
402
|
+
o.id = id + "00";
|
|
403
|
+
let runPromise;
|
|
404
|
+
function runInitially() {
|
|
405
|
+
o.dispose(false);
|
|
406
|
+
return runWithOwner(o, () => {
|
|
407
|
+
try {
|
|
408
|
+
return ctx.resolve(flatten(props.children));
|
|
409
|
+
} catch (err) {
|
|
410
|
+
runPromise = ssrHandleError(err);
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
let ret = runInitially();
|
|
415
|
+
if (!(runPromise || ret?.p?.length)) return ret;
|
|
416
|
+
const fallbackOwner = createOwner({
|
|
417
|
+
id
|
|
418
|
+
});
|
|
419
|
+
getNextChildId(fallbackOwner);
|
|
420
|
+
if (ctx.async) {
|
|
421
|
+
const done = ctx.registerFragment(id);
|
|
422
|
+
(async () => {
|
|
423
|
+
while (runPromise) {
|
|
424
|
+
await runPromise;
|
|
425
|
+
runPromise = undefined;
|
|
426
|
+
ret = runInitially();
|
|
427
|
+
}
|
|
428
|
+
while (ret.p.length) {
|
|
429
|
+
await Promise.all(ret.p);
|
|
430
|
+
ret = ctx.ssr(ret.t, ...ret.h);
|
|
431
|
+
}
|
|
432
|
+
done(ret.t[0]);
|
|
433
|
+
})();
|
|
434
|
+
return runWithOwner(fallbackOwner, () => ctx.ssr([`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`], ctx.escape(props.fallback)));
|
|
435
|
+
}
|
|
436
|
+
ctx.serialize(id, "$$f");
|
|
437
|
+
return runWithOwner(fallbackOwner, () => props.fallback);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const DEV = undefined;
|
|
441
|
+
|
|
442
|
+
export { $DEVCOMP, DEV, Errored, For, Loading, Match, Repeat, Show, Switch, action, children, createComponent, createContext, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, lazy, mapArray, onSettled, pending, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
|
package/dist/solid.cjs
CHANGED
|
@@ -28,27 +28,6 @@ function children(fn) {
|
|
|
28
28
|
return memo;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function tryCatch(fn) {
|
|
32
|
-
try {
|
|
33
|
-
const v = fn();
|
|
34
|
-
if (v instanceof Promise) {
|
|
35
|
-
return v.then(v => [undefined, v], e => {
|
|
36
|
-
if (e instanceof signals.NotReadyError) throw e;
|
|
37
|
-
return [e];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return [undefined, v];
|
|
41
|
-
} catch (e) {
|
|
42
|
-
if (e instanceof signals.NotReadyError) throw e;
|
|
43
|
-
return [e];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function reducer(source, reducerFn) {
|
|
47
|
-
return [source[0], action => {
|
|
48
|
-
source[1](s => reducerFn(s, action));
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
31
|
const sharedConfig = {
|
|
53
32
|
hydrating: false,
|
|
54
33
|
registry: undefined,
|
|
@@ -59,6 +38,77 @@ const sharedConfig = {
|
|
|
59
38
|
return signals.getNextChildId(o);
|
|
60
39
|
}
|
|
61
40
|
};
|
|
41
|
+
let _createMemo;
|
|
42
|
+
let _createSignal;
|
|
43
|
+
class MockPromise {
|
|
44
|
+
static all() {
|
|
45
|
+
return new MockPromise();
|
|
46
|
+
}
|
|
47
|
+
static allSettled() {
|
|
48
|
+
return new MockPromise();
|
|
49
|
+
}
|
|
50
|
+
static any() {
|
|
51
|
+
return new MockPromise();
|
|
52
|
+
}
|
|
53
|
+
static race() {
|
|
54
|
+
return new MockPromise();
|
|
55
|
+
}
|
|
56
|
+
static reject() {
|
|
57
|
+
return new MockPromise();
|
|
58
|
+
}
|
|
59
|
+
static resolve() {
|
|
60
|
+
return new MockPromise();
|
|
61
|
+
}
|
|
62
|
+
catch() {
|
|
63
|
+
return new MockPromise();
|
|
64
|
+
}
|
|
65
|
+
then() {
|
|
66
|
+
return new MockPromise();
|
|
67
|
+
}
|
|
68
|
+
finally() {
|
|
69
|
+
return new MockPromise();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function subFetch(fn, prev) {
|
|
73
|
+
const ogFetch = fetch;
|
|
74
|
+
const ogPromise = Promise;
|
|
75
|
+
try {
|
|
76
|
+
window.fetch = () => new MockPromise();
|
|
77
|
+
Promise = MockPromise;
|
|
78
|
+
return fn(prev);
|
|
79
|
+
} finally {
|
|
80
|
+
window.fetch = ogFetch;
|
|
81
|
+
Promise = ogPromise;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function hydratedCreateMemo(compute, value, options) {
|
|
85
|
+
if (!sharedConfig.hydrating) return signals.createMemo(compute, value, options);
|
|
86
|
+
return signals.createMemo(prev => {
|
|
87
|
+
const o = signals.getOwner();
|
|
88
|
+
if (!sharedConfig.hydrating) return compute(prev);
|
|
89
|
+
let initP;
|
|
90
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
91
|
+
const init = initP?.v ?? initP;
|
|
92
|
+
return init != null ? (subFetch(compute, prev), init) : compute(prev);
|
|
93
|
+
}, value, options);
|
|
94
|
+
}
|
|
95
|
+
function hydratedCreateSignal(fn, second, third) {
|
|
96
|
+
if (typeof fn !== "function" || !sharedConfig.hydrating) return signals.createSignal(fn, second, third);
|
|
97
|
+
return signals.createSignal(prev => {
|
|
98
|
+
if (!sharedConfig.hydrating) return fn(prev);
|
|
99
|
+
const o = signals.getOwner();
|
|
100
|
+
let initP;
|
|
101
|
+
if (sharedConfig.has(o.id)) initP = sharedConfig.load(o.id);
|
|
102
|
+
const init = initP?.v ?? initP;
|
|
103
|
+
return init != null ? (subFetch(fn, prev), init) : fn(prev);
|
|
104
|
+
}, second, third);
|
|
105
|
+
}
|
|
106
|
+
function enableHydration() {
|
|
107
|
+
_createMemo = hydratedCreateMemo;
|
|
108
|
+
_createSignal = hydratedCreateSignal;
|
|
109
|
+
}
|
|
110
|
+
const createMemo = (...args) => (_createMemo || signals.createMemo)(...args);
|
|
111
|
+
const createSignal = (...args) => (_createSignal || signals.createSignal)(...args);
|
|
62
112
|
function Loading(props) {
|
|
63
113
|
if (!sharedConfig.hydrating) return signals.createLoadBoundary(() => props.children, () => props.fallback);
|
|
64
114
|
return signals.createMemo(() => {
|
|
@@ -68,7 +118,7 @@ function Loading(props) {
|
|
|
68
118
|
let ref = sharedConfig.load(id);
|
|
69
119
|
let p;
|
|
70
120
|
if (ref) {
|
|
71
|
-
if (typeof ref !== "object" || ref.s !==
|
|
121
|
+
if (typeof ref !== "object" || ref.s !== 1) p = ref;else sharedConfig.gather(id);
|
|
72
122
|
}
|
|
73
123
|
if (p) {
|
|
74
124
|
const [s, set] = signals.createSignal(undefined, {
|
|
@@ -93,8 +143,6 @@ function Loading(props) {
|
|
|
93
143
|
});
|
|
94
144
|
}
|
|
95
145
|
|
|
96
|
-
function enableHydration() {
|
|
97
|
-
}
|
|
98
146
|
function createComponent(Comp, props) {
|
|
99
147
|
return signals.untrack(() => Comp(props || {}));
|
|
100
148
|
}
|
|
@@ -190,9 +238,6 @@ function Errored(props) {
|
|
|
190
238
|
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
191
239
|
});
|
|
192
240
|
}
|
|
193
|
-
function Boundary(props) {
|
|
194
|
-
return signals.createBoundary(() => props.children, () => props.mode);
|
|
195
|
-
}
|
|
196
241
|
|
|
197
242
|
function ssrHandleError() {}
|
|
198
243
|
function ssrRunInScope() {}
|
|
@@ -206,6 +251,10 @@ Object.defineProperty(exports, "$TRACK", {
|
|
|
206
251
|
enumerable: true,
|
|
207
252
|
get: function () { return signals.$TRACK; }
|
|
208
253
|
});
|
|
254
|
+
Object.defineProperty(exports, "NotReadyError", {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () { return signals.NotReadyError; }
|
|
257
|
+
});
|
|
209
258
|
Object.defineProperty(exports, "action", {
|
|
210
259
|
enumerable: true,
|
|
211
260
|
get: function () { return signals.action; }
|
|
@@ -214,10 +263,6 @@ Object.defineProperty(exports, "createEffect", {
|
|
|
214
263
|
enumerable: true,
|
|
215
264
|
get: function () { return signals.createEffect; }
|
|
216
265
|
});
|
|
217
|
-
Object.defineProperty(exports, "createMemo", {
|
|
218
|
-
enumerable: true,
|
|
219
|
-
get: function () { return signals.createMemo; }
|
|
220
|
-
});
|
|
221
266
|
Object.defineProperty(exports, "createOptimistic", {
|
|
222
267
|
enumerable: true,
|
|
223
268
|
get: function () { return signals.createOptimistic; }
|
|
@@ -242,10 +287,6 @@ Object.defineProperty(exports, "createRoot", {
|
|
|
242
287
|
enumerable: true,
|
|
243
288
|
get: function () { return signals.createRoot; }
|
|
244
289
|
});
|
|
245
|
-
Object.defineProperty(exports, "createSignal", {
|
|
246
|
-
enumerable: true,
|
|
247
|
-
get: function () { return signals.createSignal; }
|
|
248
|
-
});
|
|
249
290
|
Object.defineProperty(exports, "createStore", {
|
|
250
291
|
enumerable: true,
|
|
251
292
|
get: function () { return signals.createStore; }
|
|
@@ -343,7 +384,6 @@ Object.defineProperty(exports, "untrack", {
|
|
|
343
384
|
get: function () { return signals.untrack; }
|
|
344
385
|
});
|
|
345
386
|
exports.$DEVCOMP = $DEVCOMP;
|
|
346
|
-
exports.Boundary = Boundary;
|
|
347
387
|
exports.DEV = DEV;
|
|
348
388
|
exports.Errored = Errored;
|
|
349
389
|
exports.For = For;
|
|
@@ -355,12 +395,12 @@ exports.Switch = Switch;
|
|
|
355
395
|
exports.children = children;
|
|
356
396
|
exports.createComponent = createComponent;
|
|
357
397
|
exports.createContext = createContext;
|
|
398
|
+
exports.createMemo = createMemo;
|
|
399
|
+
exports.createSignal = createSignal;
|
|
358
400
|
exports.createUniqueId = createUniqueId;
|
|
359
401
|
exports.enableHydration = enableHydration;
|
|
360
402
|
exports.lazy = lazy;
|
|
361
|
-
exports.reducer = reducer;
|
|
362
403
|
exports.sharedConfig = sharedConfig;
|
|
363
404
|
exports.ssrHandleError = ssrHandleError;
|
|
364
405
|
exports.ssrRunInScope = ssrRunInScope;
|
|
365
|
-
exports.tryCatch = tryCatch;
|
|
366
406
|
exports.useContext = useContext;
|