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