@mintjamsinc/ichigojs 0.1.88 → 0.1.89

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/ichigo.cjs CHANGED
@@ -10801,8 +10801,7 @@
10801
10801
  const changed = this.bindings.isAffected(changes, this.#textEvaluator.identifiers, this.#textEvaluator.trackedPaths);
10802
10802
  // If the text node has changed, update its content
10803
10803
  if (changed) {
10804
- const text = this.#node;
10805
- text.data = this.#textEvaluator.evaluate(this.bindings);
10804
+ this.#renderText();
10806
10805
  }
10807
10806
  }
10808
10807
  else if (this.#nodeType === Node.ELEMENT_NODE) {
@@ -10823,7 +10822,7 @@
10823
10822
  for (const preparer of this.#directiveManager.bindingsPreparers) {
10824
10823
  const changed = this.bindings.isAffected(changes, preparer.dependentIdentifiers, preparer.trackedPaths);
10825
10824
  if (changed) {
10826
- preparer.prepareBindings();
10825
+ this.#renderSafely(() => preparer.prepareBindings());
10827
10826
  }
10828
10827
  }
10829
10828
  }
@@ -10832,7 +10831,7 @@
10832
10831
  for (const updater of this.#directiveManager.domUpdaters) {
10833
10832
  const changed = this.bindings.isAffected(changes, updater.dependentIdentifiers, updater.trackedPaths);
10834
10833
  if (changed) {
10835
- updater.applyToDOM();
10834
+ this.#renderSafely(() => updater.applyToDOM());
10836
10835
  }
10837
10836
  }
10838
10837
  }
@@ -10870,8 +10869,7 @@
10870
10869
  forceUpdate() {
10871
10870
  if (this.#nodeType === Node.TEXT_NODE && this.#textEvaluator) {
10872
10871
  // If this is a text node with a text evaluator, update its content if needed
10873
- const text = this.#node;
10874
- text.data = this.#textEvaluator.evaluate(this.bindings);
10872
+ this.#renderText();
10875
10873
  }
10876
10874
  else if (this.#nodeType === Node.ELEMENT_NODE) {
10877
10875
  // If this is an element node, update directives and child nodes
@@ -10889,13 +10887,13 @@
10889
10887
  }
10890
10888
  // Prepare bindings for each preparer if relevant identifiers have changed
10891
10889
  for (const preparer of this.#directiveManager.bindingsPreparers) {
10892
- preparer.prepareBindings();
10890
+ this.#renderSafely(() => preparer.prepareBindings());
10893
10891
  }
10894
10892
  }
10895
10893
  // Apply DOM updaters from directives, if any
10896
10894
  if (this.#directiveManager?.domUpdaters) {
10897
10895
  for (const updater of this.#directiveManager.domUpdaters) {
10898
- updater.applyToDOM();
10896
+ this.#renderSafely(() => updater.applyToDOM());
10899
10897
  }
10900
10898
  }
10901
10899
  // Recursively update child virtual nodes. A copy: an update can
@@ -10917,6 +10915,38 @@
10917
10915
  });
10918
10916
  }
10919
10917
  }
10918
+ /**
10919
+ * Evaluates this text node's expressions into its content.
10920
+ */
10921
+ #renderText() {
10922
+ const text = this.#node;
10923
+ this.#renderSafely(() => {
10924
+ text.data = this.#textEvaluator.evaluate(this.bindings);
10925
+ });
10926
+ }
10927
+ /**
10928
+ * Runs one binding's render step. A binding whose expression throws (for example one that
10929
+ * reads a member of a value that is still undefined) is logged and left as it was, so that
10930
+ * it does not stop the rest of the tree from rendering.
10931
+ * @param render The render step.
10932
+ */
10933
+ #renderSafely(render) {
10934
+ try {
10935
+ render();
10936
+ }
10937
+ catch (error) {
10938
+ this.#vApplication.logManager.getLogger(this.constructor.name).error(`Error rendering ${this.#describe()}: ${error}`);
10939
+ }
10940
+ }
10941
+ /**
10942
+ * Describes this node for a log message: a text node by its text, an element by its tag.
10943
+ */
10944
+ #describe() {
10945
+ if (this.#nodeType === Node.TEXT_NODE) {
10946
+ return `text "${(this.#node.textContent ?? '').trim()}"`;
10947
+ }
10948
+ return `<${this.#nodeName.toLowerCase()}>`;
10949
+ }
10920
10950
  /**
10921
10951
  * Adds a child virtual node to this virtual node.
10922
10952
  * @param child The child virtual node to add.
@@ -15643,8 +15673,11 @@
15643
15673
  vApplication: this,
15644
15674
  bindings: this.#bindings
15645
15675
  });
15646
- // Initial rendering
15647
- this.#vNode.update();
15676
+ // Initial rendering. Every binding is applied, not only those whose identifiers were
15677
+ // recorded as changed while the data was set up: a value that starts undefined is never
15678
+ // recorded (undefined -> undefined is no change), and an expression over globals only
15679
+ // has no identifier to record at all.
15680
+ this.#vNode.forceUpdate();
15648
15681
  // Expand the components in the tree. Last, so every component element
15649
15682
  // has been compiled and has had its prop values delivered before its
15650
15683
  // template is cloned in. See VNode.expandComponents.