solid-js 1.8.0-beta.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/dev.js +532 -297
  2. package/dist/server.js +168 -74
  3. package/dist/solid.js +459 -255
  4. package/h/dist/h.js +34 -8
  5. package/h/jsx-runtime/dist/jsx.js +1 -1
  6. package/h/jsx-runtime/types/index.d.ts +11 -8
  7. package/h/types/hyperscript.d.ts +11 -11
  8. package/html/dist/html.js +216 -94
  9. package/html/types/lit.d.ts +45 -31
  10. package/package.json +1 -1
  11. package/store/dist/dev.js +114 -42
  12. package/store/dist/server.js +19 -8
  13. package/store/dist/store.js +105 -39
  14. package/store/types/index.d.ts +21 -7
  15. package/store/types/modifiers.d.ts +6 -3
  16. package/store/types/mutable.d.ts +5 -2
  17. package/store/types/server.d.ts +12 -4
  18. package/store/types/store.d.ts +218 -61
  19. package/types/index.d.ts +72 -9
  20. package/types/reactive/array.d.ts +12 -4
  21. package/types/reactive/observable.d.ts +25 -17
  22. package/types/reactive/scheduler.d.ts +9 -6
  23. package/types/reactive/signal.d.ts +228 -140
  24. package/types/render/Suspense.d.ts +5 -5
  25. package/types/render/component.d.ts +62 -31
  26. package/types/render/flow.d.ts +43 -31
  27. package/types/render/hydration.d.ts +13 -13
  28. package/types/server/index.d.ts +56 -2
  29. package/types/server/reactive.d.ts +67 -40
  30. package/types/server/rendering.d.ts +166 -95
  31. package/universal/dist/dev.js +28 -12
  32. package/universal/dist/universal.js +28 -12
  33. package/universal/types/index.d.ts +3 -1
  34. package/universal/types/universal.d.ts +0 -1
  35. package/web/dist/dev.js +611 -79
  36. package/web/dist/server.js +175 -92
  37. package/web/dist/web.js +611 -79
  38. package/web/types/client.d.ts +2 -2
  39. package/web/types/core.d.ts +10 -1
  40. package/web/types/index.d.ts +27 -10
  41. package/web/types/server-mock.d.ts +47 -32
package/dist/server.js CHANGED
@@ -17,7 +17,7 @@ function handleError(err, owner = Owner) {
17
17
  try {
18
18
  for (const f of fns) f(error);
19
19
  } catch (e) {
20
- handleError(e, owner && owner.owner || null);
20
+ handleError(e, (owner && owner.owner) || null);
21
21
  }
22
22
  }
23
23
  const UNOWNED = {
@@ -35,19 +35,23 @@ function createOwner() {
35
35
  cleanups: null
36
36
  };
37
37
  if (Owner) {
38
- if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o);
38
+ if (!Owner.owned) Owner.owned = [o];
39
+ else Owner.owned.push(o);
39
40
  }
40
41
  return o;
41
42
  }
42
43
  function createRoot(fn, detachedOwner) {
43
44
  const owner = Owner,
44
45
  current = detachedOwner === undefined ? owner : detachedOwner,
45
- root = fn.length === 0 ? UNOWNED : {
46
- context: current ? current.context : null,
47
- owner: current,
48
- owned: null,
49
- cleanups: null
50
- };
46
+ root =
47
+ fn.length === 0
48
+ ? UNOWNED
49
+ : {
50
+ context: current ? current.context : null,
51
+ owner: current,
52
+ owned: null,
53
+ cleanups: null
54
+ };
51
55
  Owner = root;
52
56
  let result;
53
57
  try {
@@ -60,9 +64,12 @@ function createRoot(fn, detachedOwner) {
60
64
  return result;
61
65
  }
62
66
  function createSignal(value, options) {
63
- return [() => value, v => {
64
- return value = typeof v === "function" ? v(value) : v;
65
- }];
67
+ return [
68
+ () => value,
69
+ v => {
70
+ return (value = typeof v === "function" ? v(value) : v);
71
+ }
72
+ ];
66
73
  }
67
74
  function createComputed(fn, value) {
68
75
  Owner = createOwner();
@@ -119,7 +126,8 @@ function on(deps, fn, options = {}) {
119
126
  function onMount(fn) {}
120
127
  function onCleanup(fn) {
121
128
  if (Owner) {
122
- if (!Owner.cleanups) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
129
+ if (!Owner.cleanups) Owner.cleanups = [fn];
130
+ else Owner.cleanups.push(fn);
123
131
  }
124
132
  return fn;
125
133
  }
@@ -160,7 +168,9 @@ function createContext(defaultValue) {
160
168
  };
161
169
  }
162
170
  function useContext(context) {
163
- return Owner && Owner.context && Owner.context[context.id] !== undefined ? Owner.context[context.id] : context.defaultValue;
171
+ return Owner && Owner.context && Owner.context[context.id] !== undefined
172
+ ? Owner.context[context.id]
173
+ : context.defaultValue;
164
174
  }
165
175
  function getOwner() {
166
176
  return Owner;
@@ -229,7 +239,8 @@ function observable(input) {
229
239
  if (!(observer instanceof Object) || observer == null) {
230
240
  throw new TypeError("Expected the observer to be an object.");
231
241
  }
232
- const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
242
+ const handler =
243
+ typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
233
244
  if (!handler) {
234
245
  return {
235
246
  unsubscribe() {}
@@ -258,7 +269,7 @@ function from(producer) {
258
269
  const [s, set] = createSignal(undefined);
259
270
  if ("subscribe" in producer) {
260
271
  const unsub = producer.subscribe(v => set(() => v));
261
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
272
+ onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
262
273
  } else {
263
274
  const clean = producer(set);
264
275
  onCleanup(clean);
@@ -310,11 +321,13 @@ function setHydrateContext(context) {
310
321
  sharedConfig.context = context;
311
322
  }
312
323
  function nextHydrateContext() {
313
- return sharedConfig.context ? {
314
- ...sharedConfig.context,
315
- id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`,
316
- count: 0
317
- } : undefined;
324
+ return sharedConfig.context
325
+ ? {
326
+ ...sharedConfig.context,
327
+ id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`,
328
+ count: 0
329
+ }
330
+ : undefined;
318
331
  }
319
332
  function createUniqueId() {
320
333
  const ctx = sharedConfig.context;
@@ -391,7 +404,11 @@ function Index(props) {
391
404
  }
392
405
  function Show(props) {
393
406
  let c;
394
- return props.when ? typeof (c = props.children) === "function" ? c(props.keyed ? props.when : () => props.when) : c : props.fallback || "";
407
+ return props.when
408
+ ? typeof (c = props.children) === "function"
409
+ ? c(props.keyed ? props.when : () => props.when)
410
+ : c
411
+ : props.fallback || "";
395
412
  }
396
413
  function Switch(props) {
397
414
  let conditions = props.children;
@@ -428,11 +445,14 @@ function ErrorBoundary(props) {
428
445
  }
429
446
  createMemo(() => {
430
447
  clean = Owner;
431
- return catchError(() => res = props.children, err => {
432
- error = err;
433
- !sync && ctx.replace("e" + id, displayFallback);
434
- sync = true;
435
- });
448
+ return catchError(
449
+ () => (res = props.children),
450
+ err => {
451
+ error = err;
452
+ !sync && ctx.replace("e" + id, displayFallback);
453
+ sync = true;
454
+ }
455
+ );
436
456
  });
437
457
  if (error) return displayFallback();
438
458
  sync = false;
@@ -462,14 +482,18 @@ function createResource(source, fetcher, options = {}) {
462
482
  if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
463
483
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
464
484
  if (resource.ref) {
465
- if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
485
+ if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error)
486
+ resource.ref[1].refetch();
466
487
  return resource.ref;
467
488
  }
468
489
  }
469
490
  const read = () => {
470
491
  if (error) throw error;
471
492
  if (resourceContext && p) resourceContext.push(p);
472
- const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
493
+ const resolved =
494
+ options.ssrLoadFrom !== "initial" &&
495
+ sharedConfig.context.async &&
496
+ "data" in sharedConfig.context.resources[id];
473
497
  if (!resolved && read.loading) {
474
498
  const ctx = useContext(SuspenseContext);
475
499
  if (ctx) {
@@ -489,7 +513,7 @@ function createResource(source, fetcher, options = {}) {
489
513
  });
490
514
  function load() {
491
515
  const ctx = sharedConfig.context;
492
- if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
516
+ if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source));
493
517
  if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
494
518
  value = ctx.resources[id].data;
495
519
  return;
@@ -497,9 +521,11 @@ function createResource(source, fetcher, options = {}) {
497
521
  resourceContext = [];
498
522
  const lookup = typeof source === "function" ? source() : source;
499
523
  if (resourceContext.length) {
500
- p = Promise.all(resourceContext).then(() => fetcher(source(), {
501
- value
502
- }));
524
+ p = Promise.all(resourceContext).then(() =>
525
+ fetcher(source(), {
526
+ value
527
+ })
528
+ );
503
529
  }
504
530
  resourceContext = null;
505
531
  if (!p) {
@@ -512,20 +538,22 @@ function createResource(source, fetcher, options = {}) {
512
538
  read.loading = true;
513
539
  read.state = "pending";
514
540
  if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
515
- return p.then(res => {
516
- read.loading = false;
517
- read.state = "ready";
518
- ctx.resources[id].data = res;
519
- p = null;
520
- notifySuspense(contexts);
521
- return res;
522
- }).catch(err => {
523
- read.loading = false;
524
- read.state = "errored";
525
- read.error = error = castError(err);
526
- p = null;
527
- notifySuspense(contexts);
528
- });
541
+ return p
542
+ .then(res => {
543
+ read.loading = false;
544
+ read.state = "ready";
545
+ ctx.resources[id].data = res;
546
+ p = null;
547
+ notifySuspense(contexts);
548
+ return res;
549
+ })
550
+ .catch(err => {
551
+ read.loading = false;
552
+ read.state = "errored";
553
+ read.error = error = castError(err);
554
+ p = null;
555
+ notifySuspense(contexts);
556
+ });
529
557
  }
530
558
  ctx.resources[id].data = p;
531
559
  if (ctx.serialize) ctx.serialize(id, p);
@@ -533,17 +561,20 @@ function createResource(source, fetcher, options = {}) {
533
561
  return ctx.resources[id].data;
534
562
  }
535
563
  if (options.ssrLoadFrom !== "initial") load();
536
- return resource.ref = [read, {
537
- refetch: load,
538
- mutate: v => value = v
539
- }];
564
+ return (resource.ref = [
565
+ read,
566
+ {
567
+ refetch: load,
568
+ mutate: v => (value = v)
569
+ }
570
+ ]);
540
571
  }
541
572
  function lazy(fn) {
542
573
  let p;
543
574
  let load = id => {
544
575
  if (!p) {
545
576
  p = fn();
546
- p.then(mod => p.resolved = mod.default);
577
+ p.then(mod => (p.resolved = mod.default));
547
578
  if (id) sharedConfig.context.lazy[id] = p;
548
579
  }
549
580
  return p;
@@ -552,7 +583,8 @@ function lazy(fn) {
552
583
  const wrap = props => {
553
584
  const id = sharedConfig.context.id.slice(0, -1);
554
585
  let ref = sharedConfig.context.lazy[id];
555
- if (ref) p = ref;else load(id);
586
+ if (ref) p = ref;
587
+ else load(id);
556
588
  if (p.resolved) return p.resolved(props);
557
589
  const ctx = useContext(SuspenseContext);
558
590
  const track = {
@@ -564,10 +596,12 @@ function lazy(fn) {
564
596
  contexts.add(ctx);
565
597
  }
566
598
  if (sharedConfig.context.async) {
567
- sharedConfig.context.block(p.then(() => {
568
- track.loading = false;
569
- notifySuspense(contexts);
570
- }));
599
+ sharedConfig.context.block(
600
+ p.then(() => {
601
+ track.loading = false;
602
+ notifySuspense(contexts);
603
+ })
604
+ );
571
605
  }
572
606
  return "";
573
607
  };
@@ -595,9 +629,12 @@ function startTransition(fn) {
595
629
  fn();
596
630
  }
597
631
  function useTransition() {
598
- return [() => false, fn => {
599
- fn();
600
- }];
632
+ return [
633
+ () => false,
634
+ fn => {
635
+ fn();
636
+ }
637
+ ];
601
638
  }
602
639
  function SuspenseList(props) {
603
640
  return props.children;
@@ -607,15 +644,17 @@ function Suspense(props) {
607
644
  const ctx = sharedConfig.context;
608
645
  const id = ctx.id + ctx.count;
609
646
  const o = createOwner();
610
- const value = ctx.suspense[id] || (ctx.suspense[id] = {
611
- resources: new Map(),
612
- completed: () => {
613
- const res = runSuspense();
614
- if (suspenseComplete(value)) {
615
- done(resolveSSRNode(res));
647
+ const value =
648
+ ctx.suspense[id] ||
649
+ (ctx.suspense[id] = {
650
+ resources: new Map(),
651
+ completed: () => {
652
+ const res = runSuspense();
653
+ if (suspenseComplete(value)) {
654
+ done(resolveSSRNode(res));
655
+ }
616
656
  }
617
- }
618
- });
657
+ });
619
658
  function suspenseError(err) {
620
659
  if (!done || !done(undefined, err)) {
621
660
  runWithOwner(o.owner, () => {
@@ -629,12 +668,14 @@ function Suspense(props) {
629
668
  count: 0
630
669
  });
631
670
  cleanNode(o);
632
- return runWithOwner(o, () => createComponent(SuspenseContext.Provider, {
633
- value,
634
- get children() {
635
- return catchError(() => props.children, suspenseError);
636
- }
637
- }));
671
+ return runWithOwner(o, () =>
672
+ createComponent(SuspenseContext.Provider, {
673
+ value,
674
+ get children() {
675
+ return catchError(() => props.children, suspenseError);
676
+ }
677
+ })
678
+ );
638
679
  }
639
680
  const res = runSuspense();
640
681
  if (suspenseComplete(value)) return res;
@@ -663,4 +704,57 @@ function Suspense(props) {
663
704
  }, suspenseError);
664
705
  }
665
706
 
666
- export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, catchError, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
707
+ export {
708
+ $DEVCOMP,
709
+ $PROXY,
710
+ $TRACK,
711
+ DEV,
712
+ ErrorBoundary,
713
+ For,
714
+ Index,
715
+ Match,
716
+ Show,
717
+ Suspense,
718
+ SuspenseList,
719
+ Switch,
720
+ batch,
721
+ catchError,
722
+ children,
723
+ createComponent,
724
+ createComputed,
725
+ createContext,
726
+ createDeferred,
727
+ createEffect,
728
+ createMemo,
729
+ createReaction,
730
+ createRenderEffect,
731
+ createResource,
732
+ createRoot,
733
+ createSelector,
734
+ createSignal,
735
+ createUniqueId,
736
+ enableExternalSource,
737
+ enableHydration,
738
+ enableScheduling,
739
+ equalFn,
740
+ from,
741
+ getListener,
742
+ getOwner,
743
+ lazy,
744
+ mapArray,
745
+ mergeProps,
746
+ observable,
747
+ on,
748
+ onCleanup,
749
+ onError,
750
+ onMount,
751
+ requestCallback,
752
+ resetErrorBoundaries,
753
+ runWithOwner,
754
+ sharedConfig,
755
+ splitProps,
756
+ startTransition,
757
+ untrack,
758
+ useContext,
759
+ useTransition
760
+ };