@niscorp/solid 0.1.0 → 0.1.2

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/index.js CHANGED
@@ -106,6 +106,7 @@ var createIncrementalParser = (base, opts = {}) => {
106
106
  }
107
107
  };
108
108
  const setValue = (value) => {
109
+ if (containerStack.length === 0) return;
109
110
  const container = topContainer();
110
111
  let existing;
111
112
  if (topContainerType() === "object") {
@@ -464,6 +465,13 @@ var createIncrementalParser = (base, opts = {}) => {
464
465
  isDirty = false;
465
466
  return { changed: true, value };
466
467
  };
468
+ const detachValue = (value) => {
469
+ if (Array.isArray(value)) return value.map(detachValue);
470
+ if (typeof value === "object" && value !== null) {
471
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, detachValue(child)]));
472
+ }
473
+ return value;
474
+ };
467
475
  const shareStructure = (source, previous, path) => {
468
476
  const dirtyKeys = dirtyParents.get(path);
469
477
  if (!dirtyKeys) return previous;
@@ -474,7 +482,7 @@ var createIncrementalParser = (base, opts = {}) => {
474
482
  const key = String(i);
475
483
  if (dirtyKeys.has(key)) {
476
484
  const childPath = path === "" ? key : `${path}.${key}`;
477
- result[i] = dirtyParents.has(childPath) ? shareStructure(source[i], prevArr[i], childPath) : source[i];
485
+ result[i] = dirtyParents.has(childPath) ? shareStructure(source[i], prevArr[i], childPath) : detachValue(source[i]);
478
486
  } else {
479
487
  result[i] = i < prevArr.length ? prevArr[i] : source[i];
480
488
  }
@@ -488,7 +496,7 @@ var createIncrementalParser = (base, opts = {}) => {
488
496
  for (const key of Object.keys(sObj)) {
489
497
  if (dirtyKeys.has(key)) {
490
498
  const childPath = path === "" ? key : `${path}.${key}`;
491
- result[key] = dirtyParents.has(childPath) ? shareStructure(sObj[key], pObj[key], childPath) : sObj[key];
499
+ result[key] = dirtyParents.has(childPath) ? shareStructure(sObj[key], pObj[key], childPath) : detachValue(sObj[key]);
492
500
  } else {
493
501
  result[key] = key in pObj ? pObj[key] : sObj[key];
494
502
  }
@@ -729,6 +737,7 @@ var createSelectedStream = (deps) => {
729
737
  const onFinal = (listener) => {
730
738
  if (isDestroyed) return () => {
731
739
  };
740
+ if (!finalState.resolved && deps.hasRootFinalized()) resolveFinal(project());
732
741
  if (finalState.resolved) {
733
742
  listener(finalState.value);
734
743
  return () => {
@@ -759,6 +768,8 @@ var createSelectedStream = (deps) => {
759
768
  errorListeners.clear();
760
769
  pendingImmediateFires.length = 0;
761
770
  if (!finalState.resolved) {
771
+ finalState.promise.catch(() => {
772
+ });
762
773
  finalState.reject(new Error("[solid] stream destroyed"));
763
774
  }
764
775
  };
@@ -1056,6 +1067,7 @@ var createStream = (options) => {
1056
1067
  let isDestroyed = false;
1057
1068
  let isFailed = false;
1058
1069
  let failureError = null;
1070
+ let hasNotifiedFinal = false;
1059
1071
  const listeners = /* @__PURE__ */ new Set();
1060
1072
  const finalListeners = /* @__PURE__ */ new Set();
1061
1073
  const errorListeners = /* @__PURE__ */ new Set();
@@ -1120,6 +1132,7 @@ var createStream = (options) => {
1120
1132
  for (const sub of finalizeSubscribers) {
1121
1133
  sub();
1122
1134
  }
1135
+ hasNotifiedFinal = true;
1123
1136
  };
1124
1137
  const write = (chunk) => {
1125
1138
  if (isClosed || isDestroyed || isFailed) return;
@@ -1162,6 +1175,8 @@ var createStream = (options) => {
1162
1175
  errorSubscribers.clear();
1163
1176
  pendingImmediateFires.length = 0;
1164
1177
  if (!finalState.resolved) {
1178
+ finalState.promise.catch(() => {
1179
+ });
1165
1180
  finalState.reject(new Error("[solid] stream destroyed"));
1166
1181
  }
1167
1182
  for (const [, selected] of selectedStreams) {
@@ -1218,6 +1233,7 @@ var createStream = (options) => {
1218
1233
  getRootValue: () => currentValue,
1219
1234
  isTerminal: () => isClosed || isDestroyed,
1220
1235
  isPathFinal: () => tracker.isFinal(path),
1236
+ hasRootFinalized: () => hasNotifiedFinal,
1221
1237
  onRootChange: (listener) => {
1222
1238
  changeSubscribers.add(listener);
1223
1239
  return () => {