solid-js 2.0.0-experimental.10 → 2.0.0-experimental.12

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/server.js CHANGED
@@ -1,511 +1 @@
1
- import { getContext, onCleanup, Owner, runWithOwner, createRoot, setContext, flatten, NotReadyError, getOwner } from '@solidjs/signals';
2
- export { $PROXY, $TRACK, createRoot, flatten, getOwner, isEqual, isWrappable, onCleanup, runWithOwner } from '@solidjs/signals';
3
1
 
4
- function onMount(fn) {
5
- createEffect();
6
- }
7
- function createContext(defaultValue, options) {
8
- const id = Symbol(options && options.name || "");
9
- function provider(props) {
10
- return createRoot(() => {
11
- setContext(provider, props.value);
12
- return children(() => props.children);
13
- });
14
- }
15
- provider.id = id;
16
- provider.defaultValue = defaultValue;
17
- return provider;
18
- }
19
- function useContext(context) {
20
- return getContext(context);
21
- }
22
- function children(fn) {
23
- const children = createMemo(fn);
24
- const memo = createMemo(() => flatten(children()));
25
- memo.toArray = () => {
26
- const c = memo();
27
- return Array.isArray(c) ? c : c != null ? [c] : [];
28
- };
29
- return memo;
30
- }
31
- function observable(input) {
32
- return {
33
- subscribe(observer) {
34
- return {
35
- unsubscribe() {}
36
- };
37
- },
38
- [Symbol.observable || "@@observable"]() {
39
- return this;
40
- }
41
- };
42
- }
43
- function from(producer) {
44
- const [s, set] = createSignal(undefined, {
45
- equals: false
46
- });
47
- if ("subscribe" in producer) {
48
- const unsub = producer.subscribe(v => set(() => v));
49
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
50
- } else {
51
- const clean = producer(set);
52
- onCleanup(clean);
53
- }
54
- return s;
55
- }
56
- function ssrRunInScope(fn) {
57
- if (Array.isArray(fn)) {
58
- const o = new Owner();
59
- return fn.map(f => runWithOwner.bind(null, o, f));
60
- }
61
- return runWithOwner.bind(null, new Owner(), fn);
62
- }
63
-
64
- const ErrorContext = {
65
- id: Symbol("ErrorContext"),
66
- defaultValue: null
67
- };
68
- function ssrHandleError(err) {
69
- if (err instanceof NotReadyError) {
70
- return err.cause;
71
- }
72
- const handler = getContext(ErrorContext);
73
- if (handler) {
74
- handler(err);
75
- return;
76
- }
77
- throw err;
78
- }
79
- const sharedConfig = {
80
- getNextContextId() {
81
- const o = getOwner();
82
- if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
83
- return o.getNextChildId();
84
- }
85
- };
86
- function createUniqueId() {
87
- return sharedConfig.getNextContextId();
88
- }
89
- function createComponent(Comp, props) {
90
- return Comp(props || {});
91
- }
92
- function For(props) {
93
- return createMemo(mapArray(() => props.each, props.children, {
94
- fallback: () => props.fallback
95
- }));
96
- }
97
- function Repeat(props) {
98
- return repeat(() => props.count, index => props.children(index), {
99
- fallback: () => props.fallback,
100
- from: () => props.from
101
- });
102
- }
103
- function Show(props) {
104
- let c;
105
- const when = props.when;
106
- return when ? typeof (c = props.children) === "function" ? c(() => when) : c : props.fallback || "";
107
- }
108
- function Switch(props) {
109
- const o = getOwner();
110
- const conditions = children(() => props.children);
111
- o.getNextChildId();
112
- return createMemo(() => {
113
- let conds = conditions();
114
- Array.isArray(conds) || (conds = [conds]);
115
- for (let i = 0; i < conds.length; i++) {
116
- const w = conds[i].when;
117
- if (w) {
118
- const c = conds[i].children;
119
- return typeof c === "function" ? c(() => w) : c;
120
- }
121
- }
122
- return props.fallback || "";
123
- });
124
- }
125
- function Match(props) {
126
- return props;
127
- }
128
- function ErrorBoundary(props) {
129
- const ctx = sharedConfig.context;
130
- let sync = true;
131
- return createMemo(() => {
132
- const o = getOwner();
133
- const id = o.id;
134
- let res;
135
- setContext(ErrorContext, err => {
136
- o.dispose(false);
137
- ctx.serialize(id, err);
138
- runWithOwner(o, () => {
139
- const f = props.fallback;
140
- res = typeof f === "function" && f.length ? f(err, () => {}) : f;
141
- !sync && ctx.replace("e" + id, () => res);
142
- });
143
- }, o);
144
- try {
145
- res = flatten(props.children);
146
- } catch (err) {
147
- ssrHandleError(err);
148
- }
149
- sync = false;
150
- return ctx.ssr([`<!--!$e${id}-->`, `<!--!$/e${id}-->`], ctx.escape(res));
151
- });
152
- }
153
- function lazy(fn) {
154
- let p;
155
- let load = id => {
156
- if (!p) {
157
- p = fn();
158
- p.then(mod => {
159
- p.v = mod.default;
160
- });
161
- }
162
- return p;
163
- };
164
- const wrap = props => {
165
- sharedConfig.getNextContextId();
166
- load();
167
- if (p.v) return p.v(props);
168
- if (sharedConfig.context.async) {
169
- sharedConfig.context.block(p.then(() => {
170
- p.s = "success";
171
- }));
172
- }
173
- const err = new NotReadyError();
174
- err.cause = p;
175
- throw err;
176
- };
177
- wrap.preload = load;
178
- return wrap;
179
- }
180
- function enableHydration() {}
181
- function Suspense(props) {
182
- const ctx = sharedConfig.context;
183
- const o = new Owner();
184
- const id = o.id;
185
- o.id += "00";
186
- let runPromise;
187
- function runInitially() {
188
- o.dispose(false);
189
- return runWithOwner(o, () => {
190
- try {
191
- return ctx.resolve(flatten(props.children));
192
- } catch (err) {
193
- runPromise = ssrHandleError(err);
194
- }
195
- });
196
- }
197
- let ret = runInitially();
198
- if (!(runPromise || ret.p.length)) return ret;
199
- const fallbackOwner = new Owner(id);
200
- fallbackOwner.getNextChildId();
201
- if (ctx.async) {
202
- const done = ctx.registerFragment(id);
203
- (async () => {
204
- while (runPromise) {
205
- await runPromise;
206
- runPromise = undefined;
207
- ret = runInitially();
208
- }
209
- while (ret.p.length) {
210
- await Promise.all(ret.p);
211
- ret = ctx.ssr(ret.t, ...ret.h);
212
- }
213
- done(ret.t[0]);
214
- })();
215
- return runWithOwner(fallbackOwner, () => ctx.ssr([`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`], ctx.escape(props.fallback)));
216
- }
217
- ctx.serialize(id, "$$f");
218
- return runWithOwner(fallbackOwner, () => props.fallback);
219
- }
220
-
221
- class Computation extends Owner {
222
- constructor(initialValue, compute) {
223
- super();
224
- this._value = initialValue;
225
- this._compute = compute;
226
- }
227
- update() {
228
- try {
229
- this._error = undefined;
230
- runWithOwner(this, () => runWithObserver(this, () => this._value = this._compute(this._value)));
231
- } catch (err) {
232
- this._error = err;
233
- }
234
- }
235
- read() {
236
- if (this._error) {
237
- throw this._error;
238
- }
239
- return this._value;
240
- }
241
- }
242
- let Observer = null;
243
- function createSignal(first, second, third) {
244
- if (typeof first === "function") {
245
- const memo = createMemo(p => {
246
- let value = first(p ? p[0]() : second);
247
- return [() => value, v => {
248
- return value = typeof v === "function" ? v(first) : v;
249
- }];
250
- });
251
- return [() => memo()[0](), v => memo()[1](v)];
252
- }
253
- let o = getOwner();
254
- if (o?.id != null) o?.getNextChildId();
255
- return [() => first, v => {
256
- return first = typeof v === "function" ? v(first) : v;
257
- }];
258
- }
259
- function createMemo(compute, value, options) {
260
- const node = new Computation(value, compute);
261
- let v;
262
- return () => {
263
- if (v !== undefined) return v;
264
- node.update();
265
- return v = node.read();
266
- };
267
- }
268
- function createRenderEffect(compute, effect, value, options) {
269
- const node = new Computation(value, compute);
270
- node.update();
271
- try {
272
- effect(node.read(), value);
273
- } catch (err) {
274
- }
275
- }
276
- function createEffect(compute, effect, value, options) {
277
- let o = getOwner();
278
- if (o?.id !== null) o?.getNextChildId();
279
- }
280
- function createTrackedEffect(compute, options) {
281
- let o = getOwner();
282
- if (o?.id !== null) o?.getNextChildId();
283
- }
284
- function createReaction(effect, options) {
285
- return tracking => {
286
- tracking();
287
- };
288
- }
289
- function createAsync(compute, value, options) {
290
- const ctx = sharedConfig.context;
291
- const o = new Owner();
292
- const id = o.id;
293
- let uninitialized = value === undefined;
294
- let source;
295
- function processSource() {
296
- try {
297
- source = runWithOwner(o, () => runWithObserver(o, () => compute(value)));
298
- } catch (err) {
299
- if (err instanceof NotReadyError) {
300
- (source = err.cause).then(() => processSource());
301
- }
302
- return;
303
- }
304
- const iterator = source[Symbol.asyncIterator];
305
- if (source instanceof Promise) {
306
- source.then(v => {
307
- source.s = "success";
308
- return source.value = value = v;
309
- });
310
- if (ctx.serialize) ctx.serialize(id, source, options?.deferStream);
311
- return;
312
- } else if (iterator) {
313
- source = iterator().next().then(v => {
314
- source.s = "success";
315
- return source.value = value = v.value;
316
- });
317
- if (ctx.serialize) ctx.serialize(id, iterator(), options?.deferStream);
318
- return;
319
- }
320
- return () => source;
321
- }
322
- return processSource() || (() => {
323
- if (value === undefined && uninitialized) {
324
- const error = new NotReadyError();
325
- error.cause = source;
326
- throw error;
327
- }
328
- return value;
329
- });
330
- }
331
- function isPending(fn, fallback) {
332
- try {
333
- fn();
334
- return false;
335
- } catch (err) {
336
- if (err instanceof NotReadyError && arguments.length > 1) {
337
- return fallback;
338
- }
339
- throw err;
340
- }
341
- }
342
- function latest(fn, fallback) {
343
- try {
344
- return fn();
345
- } catch (err) {
346
- if (err instanceof NotReadyError && arguments.length > 1) {
347
- return fallback;
348
- }
349
- throw err;
350
- }
351
- }
352
- function resolve() {
353
- throw new Error("resolve is not implemented on the server");
354
- }
355
- function flush() {}
356
- function getObserver() {
357
- return Observer;
358
- }
359
- function runWithObserver(o, fn) {
360
- const prev = Observer;
361
- Observer = o;
362
- try {
363
- return fn();
364
- } finally {
365
- Observer = prev;
366
- }
367
- }
368
- function untrack(fn) {
369
- return fn();
370
- }
371
- function mapArray(list, mapFn, options = {}) {
372
- const root = getOwner();
373
- const id = root.getNextChildId();
374
- return () => {
375
- const items = list();
376
- let s = [];
377
- if (items && items.length) {
378
- for (let i = 0, len = items.length; i < len; i++) {
379
- const o = new Owner(id + i, true);
380
- root.append(o);
381
- s.push(runWithOwner(o, () => mapFn(() => items[i], () => i)));
382
- }
383
- } else if (options.fallback) s = [options.fallback()];
384
- return s;
385
- };
386
- }
387
- function repeat(count, mapFn, options = {}) {
388
- const len = count();
389
- const offset = options.from?.() || 0;
390
- let s = [];
391
- if (len) {
392
- for (let i = 0; i < len; i++) s.push(mapFn(i + offset));
393
- } else if (options.fallback) s = [options.fallback()];
394
- return () => s;
395
- }
396
- function transition(fn) {
397
- }
398
- function useTransition() {
399
- return [() => false, () => {}];
400
- }
401
- function createOptimistic(value) {
402
- return [() => value, v => v];
403
- }
404
-
405
- function isWrappable(obj) {
406
- return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
407
- }
408
- function unwrap(item) {
409
- return item;
410
- }
411
- function setProperty(state, property, value) {
412
- if (state[property] === value) return;
413
- if (value === undefined) {
414
- delete state[property];
415
- } else state[property] = value;
416
- }
417
- function createStore(state) {
418
- function setStore(fn) {
419
- fn(state);
420
- }
421
- return [state, setStore];
422
- }
423
- function createProjection(fn, initialValue = {}) {
424
- const [state] = createStore(initialValue);
425
- fn(state);
426
- return state;
427
- }
428
- const createOptimisticStore = createStore;
429
- function reconcile(value) {
430
- return state => {
431
- if (!isWrappable(state) || !isWrappable(value)) return value;
432
- const targetKeys = Object.keys(value);
433
- const previousKeys = Object.keys(state);
434
- for (let i = 0, len = targetKeys.length; i < len; i++) {
435
- const key = targetKeys[i];
436
- setProperty(state, key, value[key]);
437
- }
438
- for (let i = 0, len = previousKeys.length; i < len; i++) {
439
- if (value[previousKeys[i]] === undefined) setProperty(state, previousKeys[i], undefined);
440
- }
441
- return state;
442
- };
443
- }
444
- function merge(...sources) {
445
- const target = {};
446
- for (let i = 0; i < sources.length; i++) {
447
- let source = sources[i];
448
- if (typeof source === "function") source = source();
449
- if (source) {
450
- const descriptors = Object.getOwnPropertyDescriptors(source);
451
- for (const key in descriptors) {
452
- if (key in target) continue;
453
- Object.defineProperty(target, key, {
454
- enumerable: true,
455
- get() {
456
- for (let i = sources.length - 1; i >= 0; i--) {
457
- let v,
458
- s = sources[i],
459
- t = typeof s;
460
- if (t === "function") s = s();
461
- if (t === "object" && t !== null && key in s) return v;
462
- }
463
- }
464
- });
465
- }
466
- }
467
- }
468
- return target;
469
- }
470
- function omit(props, ...keys) {
471
- const descriptors = Object.getOwnPropertyDescriptors(props),
472
- descriptorKeys = Object.keys(descriptors),
473
- clone = {};
474
- for (let i = 0; i < descriptorKeys.length; i++) {
475
- const key = descriptorKeys[i];
476
- if (keys.indexOf(key) === -1) {
477
- Object.defineProperty(clone, key, descriptors[key]);
478
- delete descriptors[key];
479
- }
480
- }
481
- return clone;
482
- }
483
- function deep(store) {
484
- return store;
485
- }
486
-
487
- function tryCatch(fn) {
488
- try {
489
- const v = fn();
490
- if (v instanceof Promise) {
491
- return v.then(v => [undefined, v], e => {
492
- if (e instanceof NotReadyError) throw e;
493
- return [e];
494
- });
495
- }
496
- return [undefined, v];
497
- } catch (e) {
498
- if (e instanceof NotReadyError) throw e;
499
- return [e];
500
- }
501
- }
502
- function reducer(source, reducerFn) {
503
- return [source[0], action => {
504
- source[1](s => reducerFn(s, action));
505
- }];
506
- }
507
-
508
- const $DEVCOMP = Symbol("solid-dev-component");
509
- const DEV = undefined;
510
-
511
- export { $DEVCOMP, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createAsync, createComponent, createContext, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, from, getObserver, isPending, latest, lazy, mapArray, merge, observable, omit, onMount, reconcile, reducer, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, transition, tryCatch, untrack, unwrap, useContext, useTransition };