solid-js 1.9.4 → 1.9.6

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/solid.js CHANGED
@@ -144,6 +144,7 @@ function nextHydrateContext() {
144
144
  };
145
145
  }
146
146
 
147
+ const IS_DEV = false;
147
148
  const equalFn = (a, b) => a === b;
148
149
  const $PROXY = Symbol("solid-proxy");
149
150
  const SUPPORTS_PROXY = typeof Proxy === "function";
@@ -407,12 +408,13 @@ function createResource(pSource, pFetcher, pOptions) {
407
408
  }
408
409
  }
409
410
  });
410
- if (dynamic) createComputed(() => load(false));
411
+ let owner = Owner;
412
+ if (dynamic) createComputed(() => ((owner = Owner), load(false)));
411
413
  else load(false);
412
414
  return [
413
415
  read,
414
416
  {
415
- refetch: load,
417
+ refetch: info => runWithOwner(owner, () => load(info)),
416
418
  mutate: setValue
417
419
  }
418
420
  ];
@@ -712,7 +714,7 @@ function writeSignal(node, value, isComp) {
712
714
  }
713
715
  if (Updates.length > 10e5) {
714
716
  Updates = [];
715
- if (false);
717
+ if (IS_DEV);
716
718
  throw new Error();
717
719
  }
718
720
  }, false);
@@ -1138,8 +1140,8 @@ function observable(input) {
1138
1140
  }
1139
1141
  };
1140
1142
  }
1141
- function from(producer) {
1142
- const [s, set] = createSignal(undefined, {
1143
+ function from(producer, initalValue = undefined) {
1144
+ const [s, set] = createSignal(initalValue, {
1143
1145
  equals: false
1144
1146
  });
1145
1147
  if ("subscribe" in producer) {
@@ -1531,7 +1533,7 @@ function lazy(fn) {
1531
1533
  return createMemo(() =>
1532
1534
  (Comp = comp())
1533
1535
  ? untrack(() => {
1534
- if (false);
1536
+ if (IS_DEV);
1535
1537
  if (!ctx || sharedConfig.done) return Comp(props);
1536
1538
  const c = sharedConfig.context;
1537
1539
  setHydrateContext(ctx);
@@ -1566,9 +1568,12 @@ function Index(props) {
1566
1568
  }
1567
1569
  function Show(props) {
1568
1570
  const keyed = props.keyed;
1569
- const condition = createMemo(() => props.when, undefined, {
1570
- equals: (a, b) => (keyed ? a === b : !a === !b)
1571
- });
1571
+ const conditionValue = createMemo(() => props.when, undefined, undefined);
1572
+ const condition = keyed
1573
+ ? conditionValue
1574
+ : createMemo(conditionValue, undefined, {
1575
+ equals: (a, b) => !a === !b
1576
+ });
1572
1577
  return createMemo(
1573
1578
  () => {
1574
1579
  const c = condition();
@@ -1582,7 +1587,7 @@ function Show(props) {
1582
1587
  ? c
1583
1588
  : () => {
1584
1589
  if (!untrack(condition)) throw narrowedError("Show");
1585
- return props.when;
1590
+ return conditionValue();
1586
1591
  }
1587
1592
  )
1588
1593
  )
@@ -1595,45 +1600,48 @@ function Show(props) {
1595
1600
  );
1596
1601
  }
1597
1602
  function Switch(props) {
1598
- let keyed = false;
1599
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1600
- const conditions = children(() => props.children),
1601
- evalConditions = createMemo(
1602
- () => {
1603
- let conds = conditions();
1604
- if (!Array.isArray(conds)) conds = [conds];
1605
- for (let i = 0; i < conds.length; i++) {
1606
- const c = conds[i].when;
1607
- if (c) {
1608
- keyed = !!conds[i].keyed;
1609
- return [i, c, conds[i]];
1610
- }
1611
- }
1612
- return [-1];
1613
- },
1614
- undefined,
1615
- {
1616
- equals
1617
- }
1618
- );
1603
+ const chs = children(() => props.children);
1604
+ const switchFunc = createMemo(() => {
1605
+ const ch = chs();
1606
+ const mps = Array.isArray(ch) ? ch : [ch];
1607
+ let func = () => undefined;
1608
+ for (let i = 0; i < mps.length; i++) {
1609
+ const index = i;
1610
+ const mp = mps[i];
1611
+ const prevFunc = func;
1612
+ const conditionValue = createMemo(
1613
+ () => (prevFunc() ? undefined : mp.when),
1614
+ undefined,
1615
+ undefined
1616
+ );
1617
+ const condition = mp.keyed
1618
+ ? conditionValue
1619
+ : createMemo(conditionValue, undefined, {
1620
+ equals: (a, b) => !a === !b
1621
+ });
1622
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
1623
+ }
1624
+ return func;
1625
+ });
1619
1626
  return createMemo(
1620
1627
  () => {
1621
- const [index, when, cond] = evalConditions();
1622
- if (index < 0) return props.fallback;
1623
- const c = cond.children;
1624
- const fn = typeof c === "function" && c.length > 0;
1628
+ const sel = switchFunc()();
1629
+ if (!sel) return props.fallback;
1630
+ const [index, conditionValue, mp] = sel;
1631
+ const child = mp.children;
1632
+ const fn = typeof child === "function" && child.length > 0;
1625
1633
  return fn
1626
1634
  ? untrack(() =>
1627
- c(
1628
- keyed
1629
- ? when
1635
+ child(
1636
+ mp.keyed
1637
+ ? conditionValue()
1630
1638
  : () => {
1631
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1632
- return cond.when;
1639
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
1640
+ return conditionValue();
1633
1641
  }
1634
1642
  )
1635
1643
  )
1636
- : c;
1644
+ : child;
1637
1645
  },
1638
1646
  undefined,
1639
1647
  undefined