@b9g/crank 0.5.1 → 0.5.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/crank.cjs CHANGED
@@ -862,8 +862,8 @@ const _ContextImpl = Symbol.for("crank.ContextImpl");
862
862
  * element tree are connected via contexts. Components can use this tree to
863
863
  * communicate data upwards via events and downwards via provisions.
864
864
  *
865
- * @template [TProps=*] - The expected shape of the props passed to the
866
- * component. Used to strongly type the Context iterator methods.
865
+ * @template [T=*] - The expected shape of the props passed to the component,
866
+ * or a component function. Used to strongly type the Context iterator methods.
867
867
  * @template [TResult=*] - The readable element value type. It is used in
868
868
  * places such as the return value of refresh and the argument passed to
869
869
  * schedule and cleanup callbacks.
@@ -1020,6 +1020,11 @@ class Context {
1020
1020
  */
1021
1021
  cleanup(callback) {
1022
1022
  const ctx = this[_ContextImpl];
1023
+ if (ctx.f & IsUnmounted) {
1024
+ const value = ctx.renderer.read(getValue(ctx.ret));
1025
+ callback(value);
1026
+ return;
1027
+ }
1023
1028
  let callbacks = cleanupMap.get(ctx);
1024
1029
  if (!callbacks) {
1025
1030
  callbacks = new Set();
@@ -1430,6 +1435,9 @@ function enqueueComponentRun(ctx, hydrationData) {
1430
1435
  }
1431
1436
  catch (err) {
1432
1437
  if (!(ctx.f & IsUpdating)) {
1438
+ if (!ctx.parent) {
1439
+ throw err;
1440
+ }
1433
1441
  return propagateError(ctx.parent, err);
1434
1442
  }
1435
1443
  throw err;
@@ -1453,6 +1461,9 @@ function enqueueComponentRun(ctx, hydrationData) {
1453
1461
  }
1454
1462
  catch (err) {
1455
1463
  if (!(ctx.f & IsUpdating)) {
1464
+ if (!ctx.parent) {
1465
+ throw err;
1466
+ }
1456
1467
  return propagateError(ctx.parent, err);
1457
1468
  }
1458
1469
  throw err;
@@ -1695,7 +1706,16 @@ async function runAsyncGenComponent(ctx, iterationP, hydrationData) {
1695
1706
  // children. Sync generator components only resume when their children
1696
1707
  // have fulfilled so the element’s inflight child values will never be
1697
1708
  // defined.
1698
- oldValue = ctx.ret.inflightValue.then((value) => ctx.renderer.read(value), () => ctx.renderer.read(undefined));
1709
+ oldValue = ctx.ret.inflightValue.then((value) => ctx.renderer.read(value));
1710
+ oldValue.catch((err) => {
1711
+ if (ctx.f & IsUpdating) {
1712
+ return;
1713
+ }
1714
+ if (!ctx.parent) {
1715
+ throw err;
1716
+ }
1717
+ return propagateError(ctx.parent, err);
1718
+ });
1699
1719
  }
1700
1720
  else {
1701
1721
  oldValue = ctx.renderer.read(getValue(ctx.ret));
@@ -1773,7 +1793,10 @@ function unmountComponent(ctx) {
1773
1793
  returnComponent(ctx);
1774
1794
  }
1775
1795
  }, (err) => {
1776
- propagateError(ctx.parent, err);
1796
+ if (!ctx.parent) {
1797
+ throw err;
1798
+ }
1799
+ return propagateError(ctx.parent, err);
1777
1800
  });
1778
1801
  }
1779
1802
  else {
@@ -1796,7 +1819,10 @@ function unmountComponent(ctx) {
1796
1819
  returnComponent(ctx);
1797
1820
  }
1798
1821
  }, (err) => {
1799
- propagateError(ctx.parent, err);
1822
+ if (!ctx.parent) {
1823
+ throw err;
1824
+ }
1825
+ return propagateError(ctx.parent, err);
1800
1826
  });
1801
1827
  }
1802
1828
  else {
@@ -1814,7 +1840,12 @@ function returnComponent(ctx) {
1814
1840
  ctx.f |= IsSyncExecuting;
1815
1841
  const iteration = ctx.iterator.return();
1816
1842
  if (isPromiseLike(iteration)) {
1817
- iteration.catch((err) => propagateError(ctx.parent, err));
1843
+ iteration.catch((err) => {
1844
+ if (!ctx.parent) {
1845
+ throw err;
1846
+ }
1847
+ return propagateError(ctx.parent, err);
1848
+ });
1818
1849
  }
1819
1850
  }
1820
1851
  finally {
@@ -1927,18 +1958,23 @@ function handleChildError(ctx, err) {
1927
1958
  return updateComponentChildren(ctx, iteration.value);
1928
1959
  }
1929
1960
  function propagateError(ctx, err) {
1930
- if (ctx === undefined) {
1931
- throw err;
1932
- }
1933
1961
  let result;
1934
1962
  try {
1935
1963
  result = handleChildError(ctx, err);
1936
1964
  }
1937
1965
  catch (err) {
1966
+ if (!ctx.parent) {
1967
+ throw err;
1968
+ }
1938
1969
  return propagateError(ctx.parent, err);
1939
1970
  }
1940
1971
  if (isPromiseLike(result)) {
1941
- return result.catch((err) => propagateError(ctx.parent, err));
1972
+ return result.catch((err) => {
1973
+ if (!ctx.parent) {
1974
+ throw err;
1975
+ }
1976
+ return propagateError(ctx.parent, err);
1977
+ });
1942
1978
  }
1943
1979
  return result;
1944
1980
  }