solid-js 2.0.0-experimental.1 → 2.0.0-experimental.3

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
@@ -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;
@@ -237,7 +247,8 @@ function observable(input) {
237
247
  if (!(observer instanceof Object) || observer == null) {
238
248
  throw new TypeError("Expected the observer to be an object.");
239
249
  }
240
- const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
250
+ const handler =
251
+ typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
241
252
  if (!handler) {
242
253
  return {
243
254
  unsubscribe() {}
@@ -266,7 +277,7 @@ function from(producer) {
266
277
  const [s, set] = createSignal(undefined);
267
278
  if ("subscribe" in producer) {
268
279
  const unsub = producer.subscribe(v => set(() => v));
269
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
280
+ onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
270
281
  } else {
271
282
  const clean = producer(set);
272
283
  onCleanup(clean);
@@ -337,12 +348,13 @@ function escape(s, attr) {
337
348
  left = iDelim + 1;
338
349
  iDelim = s.indexOf(delim, left);
339
350
  } while (iDelim >= 0);
340
- } else while (iAmp >= 0) {
341
- if (left < iAmp) out += s.substring(left, iAmp);
342
- out += "&amp;";
343
- left = iAmp + 1;
344
- iAmp = s.indexOf("&", left);
345
- }
351
+ } else
352
+ while (iAmp >= 0) {
353
+ if (left < iAmp) out += s.substring(left, iAmp);
354
+ out += "&amp;";
355
+ left = iAmp + 1;
356
+ iAmp = s.indexOf("&", left);
357
+ }
346
358
  return left < s.length ? out + s.substring(left) : out;
347
359
  }
348
360
  function resolveSSRNode(node) {
@@ -354,7 +366,7 @@ function resolveSSRNode(node) {
354
366
  let mapped = "";
355
367
  for (let i = 0, len = node.length; i < len; i++) {
356
368
  if (typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`;
357
- mapped += resolveSSRNode(prev = node[i]);
369
+ mapped += resolveSSRNode((prev = node[i]));
358
370
  }
359
371
  return mapped;
360
372
  }
@@ -369,7 +381,8 @@ const sharedConfig = {
369
381
  return getContextId(this.context.count);
370
382
  },
371
383
  getNextContextId() {
372
- if (!this.context) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
384
+ if (!this.context)
385
+ throw new Error(`getNextContextId cannot be used under non-hydrating context`);
373
386
  return getContextId(this.context.count++);
374
387
  }
375
388
  };
@@ -382,11 +395,13 @@ function setHydrateContext(context) {
382
395
  sharedConfig.context = context;
383
396
  }
384
397
  function nextHydrateContext() {
385
- return sharedConfig.context ? {
386
- ...sharedConfig.context,
387
- id: sharedConfig.getNextContextId(),
388
- count: 0
389
- } : undefined;
398
+ return sharedConfig.context
399
+ ? {
400
+ ...sharedConfig.context,
401
+ id: sharedConfig.getNextContextId(),
402
+ count: 0
403
+ }
404
+ : undefined;
390
405
  }
391
406
  function createUniqueId() {
392
407
  return sharedConfig.getNextContextId();
@@ -461,7 +476,11 @@ function Index(props) {
461
476
  }
462
477
  function Show(props) {
463
478
  let c;
464
- return props.when ? typeof (c = props.children) === "function" ? c(props.keyed ? props.when : () => props.when) : c : props.fallback || "";
479
+ return props.when
480
+ ? typeof (c = props.children) === "function"
481
+ ? c(props.keyed ? props.when : () => props.when)
482
+ : c
483
+ : props.fallback || "";
465
484
  }
466
485
  function Switch(props) {
467
486
  let conditions = props.children;
@@ -498,11 +517,14 @@ function ErrorBoundary(props) {
498
517
  }
499
518
  createMemo(() => {
500
519
  clean = Owner;
501
- return catchError(() => res = props.children, err => {
502
- error = err;
503
- !sync && ctx.replace("e" + id, displayFallback);
504
- sync = true;
505
- });
520
+ return catchError(
521
+ () => (res = props.children),
522
+ err => {
523
+ error = err;
524
+ !sync && ctx.replace("e" + id, displayFallback);
525
+ sync = true;
526
+ }
527
+ );
506
528
  });
507
529
  if (error) return displayFallback();
508
530
  sync = false;
@@ -527,13 +549,17 @@ function createResource(source, fetcher, options = {}) {
527
549
  if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
528
550
  resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
529
551
  if (resource.ref) {
530
- if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch();
552
+ if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error)
553
+ resource.ref[1].refetch();
531
554
  return resource.ref;
532
555
  }
533
556
  }
534
557
  const read = () => {
535
558
  if (error) throw error;
536
- const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
559
+ const resolved =
560
+ options.ssrLoadFrom !== "initial" &&
561
+ sharedConfig.context.async &&
562
+ "data" in sharedConfig.context.resources[id];
537
563
  if (!resolved && resourceContext) resourceContext.push(id);
538
564
  if (!resolved && read.loading) {
539
565
  const ctx = useContext(SuspenseContext);
@@ -554,7 +580,7 @@ function createResource(source, fetcher, options = {}) {
554
580
  });
555
581
  function load() {
556
582
  const ctx = sharedConfig.context;
557
- if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
583
+ if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source));
558
584
  if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
559
585
  value = ctx.resources[id].data;
560
586
  return;
@@ -576,21 +602,23 @@ function createResource(source, fetcher, options = {}) {
576
602
  if (p != undefined && typeof p === "object" && "then" in p) {
577
603
  read.loading = true;
578
604
  read.state = "pending";
579
- p = p.then(res => {
580
- read.loading = false;
581
- read.state = "ready";
582
- ctx.resources[id].data = res;
583
- p = null;
584
- notifySuspense(contexts);
585
- return res;
586
- }).catch(err => {
587
- read.loading = false;
588
- read.state = "errored";
589
- read.error = error = castError(err);
590
- p = null;
591
- notifySuspense(contexts);
592
- throw error;
593
- });
605
+ p = p
606
+ .then(res => {
607
+ read.loading = false;
608
+ read.state = "ready";
609
+ ctx.resources[id].data = res;
610
+ p = null;
611
+ notifySuspense(contexts);
612
+ return res;
613
+ })
614
+ .catch(err => {
615
+ read.loading = false;
616
+ read.state = "errored";
617
+ read.error = error = castError(err);
618
+ p = null;
619
+ notifySuspense(contexts);
620
+ throw error;
621
+ });
594
622
  if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
595
623
  return p;
596
624
  }
@@ -600,17 +628,20 @@ function createResource(source, fetcher, options = {}) {
600
628
  return ctx.resources[id].data;
601
629
  }
602
630
  if (options.ssrLoadFrom !== "initial") load();
603
- return resource.ref = [read, {
604
- refetch: load,
605
- mutate: v => value = v
606
- }];
631
+ return (resource.ref = [
632
+ read,
633
+ {
634
+ refetch: load,
635
+ mutate: v => (value = v)
636
+ }
637
+ ]);
607
638
  }
608
639
  function lazy(fn) {
609
640
  let p;
610
641
  let load = id => {
611
642
  if (!p) {
612
643
  p = fn();
613
- p.then(mod => p.resolved = mod.default);
644
+ p.then(mod => (p.resolved = mod.default));
614
645
  if (id) sharedConfig.context.lazy[id] = p;
615
646
  }
616
647
  return p;
@@ -619,7 +650,8 @@ function lazy(fn) {
619
650
  const wrap = props => {
620
651
  const id = sharedConfig.context.id;
621
652
  let ref = sharedConfig.context.lazy[id];
622
- if (ref) p = ref;else load(id);
653
+ if (ref) p = ref;
654
+ else load(id);
623
655
  if (p.resolved) return p.resolved(props);
624
656
  const ctx = useContext(SuspenseContext);
625
657
  const track = {
@@ -631,10 +663,12 @@ function lazy(fn) {
631
663
  contexts.add(ctx);
632
664
  }
633
665
  if (sharedConfig.context.async) {
634
- sharedConfig.context.block(p.then(() => {
635
- track.loading = false;
636
- notifySuspense(contexts);
637
- }));
666
+ sharedConfig.context.block(
667
+ p.then(() => {
668
+ track.loading = false;
669
+ notifySuspense(contexts);
670
+ })
671
+ );
638
672
  }
639
673
  return "";
640
674
  };
@@ -662,9 +696,12 @@ function startTransition(fn) {
662
696
  fn();
663
697
  }
664
698
  function useTransition() {
665
- return [() => false, fn => {
666
- fn();
667
- }];
699
+ return [
700
+ () => false,
701
+ fn => {
702
+ fn();
703
+ }
704
+ ];
668
705
  }
669
706
  function SuspenseList(props) {
670
707
  return props.children;
@@ -674,15 +711,17 @@ function Suspense(props) {
674
711
  const ctx = sharedConfig.context;
675
712
  const id = sharedConfig.getContextId();
676
713
  const o = createOwner();
677
- const value = ctx.suspense[id] || (ctx.suspense[id] = {
678
- resources: new Map(),
679
- completed: () => {
680
- const res = runSuspense();
681
- if (suspenseComplete(value)) {
682
- done(resolveSSRNode(escape(res)));
714
+ const value =
715
+ ctx.suspense[id] ||
716
+ (ctx.suspense[id] = {
717
+ resources: new Map(),
718
+ completed: () => {
719
+ const res = runSuspense();
720
+ if (suspenseComplete(value)) {
721
+ done(resolveSSRNode(escape(res)));
722
+ }
683
723
  }
684
- }
685
- });
724
+ });
686
725
  function suspenseError(err) {
687
726
  if (!done || !done(undefined, err)) {
688
727
  runWithOwner(o.owner, () => {
@@ -696,12 +735,14 @@ function Suspense(props) {
696
735
  count: 0
697
736
  });
698
737
  cleanNode(o);
699
- return runWithOwner(o, () => createComponent(SuspenseContext.Provider, {
700
- value,
701
- get children() {
702
- return catchError(() => props.children, suspenseError);
703
- }
704
- }));
738
+ return runWithOwner(o, () =>
739
+ createComponent(SuspenseContext.Provider, {
740
+ value,
741
+ get children() {
742
+ return catchError(() => props.children, suspenseError);
743
+ }
744
+ })
745
+ );
705
746
  }
706
747
  const res = runSuspense();
707
748
  if (suspenseComplete(value)) {
@@ -718,7 +759,9 @@ function Suspense(props) {
718
759
  noHydrate: true
719
760
  });
720
761
  const res = {
721
- t: `<template id="pl-${id}"></template>${resolveSSRNode(escape(props.fallback))}<!--pl-${id}-->`
762
+ t: `<template id="pl-${id}"></template>${resolveSSRNode(
763
+ escape(props.fallback)
764
+ )}<!--pl-${id}-->`
722
765
  };
723
766
  setHydrateContext(ctx);
724
767
  return res;
@@ -767,4 +810,61 @@ function reconcile(value) {
767
810
  };
768
811
  }
769
812
 
770
- export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, catchError, children, createComponent, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createStore, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, isWrappable, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, reconcile, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, unwrap, useContext, useTransition };
813
+ export {
814
+ $DEVCOMP,
815
+ $PROXY,
816
+ $TRACK,
817
+ DEV,
818
+ ErrorBoundary,
819
+ For,
820
+ Index,
821
+ Match,
822
+ Show,
823
+ Suspense,
824
+ SuspenseList,
825
+ Switch,
826
+ batch,
827
+ catchError,
828
+ children,
829
+ createComponent,
830
+ createContext,
831
+ createDeferred,
832
+ createEffect,
833
+ createMemo,
834
+ createReaction,
835
+ createRenderEffect,
836
+ createResource,
837
+ createRoot,
838
+ createSelector,
839
+ createSignal,
840
+ createStore,
841
+ createUniqueId,
842
+ enableExternalSource,
843
+ enableHydration,
844
+ enableScheduling,
845
+ equalFn,
846
+ from,
847
+ getListener,
848
+ getOwner,
849
+ indexArray,
850
+ isWrappable,
851
+ lazy,
852
+ mapArray,
853
+ mergeProps,
854
+ observable,
855
+ on,
856
+ onCleanup,
857
+ onError,
858
+ onMount,
859
+ reconcile,
860
+ requestCallback,
861
+ resetErrorBoundaries,
862
+ runWithOwner,
863
+ sharedConfig,
864
+ splitProps,
865
+ startTransition,
866
+ untrack,
867
+ unwrap,
868
+ useContext,
869
+ useTransition
870
+ };
package/dist/solid.cjs CHANGED
@@ -61,8 +61,8 @@ function observable(input) {
61
61
  }
62
62
  };
63
63
  }
64
- function from(producer) {
65
- const [s, set] = signals.createSignal(undefined, {
64
+ function from(producer, initialValue = undefined) {
65
+ const [s, set] = signals.createSignal(() => initialValue, initialValue, {
66
66
  equals: false
67
67
  });
68
68
  if ("subscribe" in producer) {
@@ -175,8 +175,9 @@ function Repeat(props) {
175
175
  }
176
176
  function Show(props) {
177
177
  const keyed = props.keyed;
178
- const condition = signals.createMemo(() => props.when, undefined, {
179
- equals: (a, b) => keyed ? a === b : !a === !b
178
+ const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
179
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
180
+ equals: (a, b) => !a === !b
180
181
  });
181
182
  return signals.createMemo(() => {
182
183
  const c = condition();
@@ -185,39 +186,40 @@ function Show(props) {
185
186
  const fn = typeof child === "function" && child.length > 0;
186
187
  return fn ? signals.untrack(() => child(() => {
187
188
  if (!signals.untrack(condition)) throw narrowedError("Show");
188
- return props.when;
189
+ return conditionValue();
189
190
  })) : child;
190
191
  }
191
192
  return props.fallback;
192
193
  }, undefined, undefined);
193
194
  }
194
195
  function Switch(props) {
195
- let keyed = false;
196
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
197
- const conditions = children(() => props.children),
198
- evalConditions = signals.createMemo(() => {
199
- let conds = conditions();
200
- if (!Array.isArray(conds)) conds = [conds];
201
- for (let i = 0; i < conds.length; i++) {
202
- const c = conds[i].when;
203
- if (c) {
204
- keyed = !!conds[i].keyed;
205
- return [i, c, conds[i]];
206
- }
207
- }
208
- return [-1];
209
- }, undefined, {
210
- equals
211
- });
196
+ const chs = children(() => props.children);
197
+ const switchFunc = signals.createMemo(() => {
198
+ const ch = chs();
199
+ const mps = Array.isArray(ch) ? ch : [ch];
200
+ let func = () => undefined;
201
+ for (let i = 0; i < mps.length; i++) {
202
+ const index = i;
203
+ const mp = mps[i];
204
+ const prevFunc = func;
205
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
206
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
207
+ equals: (a, b) => !a === !b
208
+ });
209
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
210
+ }
211
+ return func;
212
+ });
212
213
  return signals.createMemo(() => {
213
- const [index, when, cond] = evalConditions();
214
- if (index < 0) return props.fallback;
215
- const c = cond.children;
216
- const fn = typeof c === "function" && c.length > 0;
217
- return fn ? signals.untrack(() => c(() => {
218
- if (signals.untrack(evalConditions)[0] !== index) throw narrowedError("Match");
219
- return cond.when;
220
- })) : c;
214
+ const sel = switchFunc()();
215
+ if (!sel) return props.fallback;
216
+ const [index, conditionValue, mp] = sel;
217
+ const child = mp.children;
218
+ const fn = typeof child === "function" && child.length > 0;
219
+ return fn ? signals.untrack(() => child(() => {
220
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
221
+ return conditionValue();
222
+ })) : child;
221
223
  }, undefined, undefined);
222
224
  }
223
225
  function Match(props) {
@@ -267,10 +269,6 @@ Object.defineProperty(exports, "createProjection", {
267
269
  enumerable: true,
268
270
  get: function () { return signals.createProjection; }
269
271
  });
270
- Object.defineProperty(exports, "createReaction", {
271
- enumerable: true,
272
- get: function () { return signals.createReaction; }
273
- });
274
272
  Object.defineProperty(exports, "createRenderEffect", {
275
273
  enumerable: true,
276
274
  get: function () { return signals.createRenderEffect; }
@@ -307,9 +305,9 @@ Object.defineProperty(exports, "isEqual", {
307
305
  enumerable: true,
308
306
  get: function () { return signals.isEqual; }
309
307
  });
310
- Object.defineProperty(exports, "isStale", {
308
+ Object.defineProperty(exports, "isPending", {
311
309
  enumerable: true,
312
- get: function () { return signals.isStale; }
310
+ get: function () { return signals.isPending; }
313
311
  });
314
312
  Object.defineProperty(exports, "isWrappable", {
315
313
  enumerable: true,
@@ -347,6 +345,10 @@ Object.defineProperty(exports, "resolve", {
347
345
  enumerable: true,
348
346
  get: function () { return signals.resolve; }
349
347
  });
348
+ Object.defineProperty(exports, "runWithObserver", {
349
+ enumerable: true,
350
+ get: function () { return signals.runWithObserver; }
351
+ });
350
352
  Object.defineProperty(exports, "runWithOwner", {
351
353
  enumerable: true,
352
354
  get: function () { return signals.runWithOwner; }