native-document 1.0.87 → 1.0.88

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.
@@ -69,6 +69,14 @@ export const ElementCreator = {
69
69
  }
70
70
  return Anchor('Fragment');
71
71
  },
72
+ bindTextNode(textNode, value) {
73
+ if(value?.__$isObservable) {
74
+ value.subscribe(newValue => textNode.nodeValue = newValue);
75
+ textNode.nodeValue = value.val();
76
+ return;
77
+ }
78
+ textNode.nodeValue = value;
79
+ },
72
80
  /**
73
81
  *
74
82
  * @param {*} children
@@ -1,5 +1,4 @@
1
1
  import {ElementCreator} from "./ElementCreator";
2
- import {createTextNode} from "./HtmlElementWrapper";
3
2
  import TemplateBinding from "./TemplateBinding";
4
3
 
5
4
  const cloneBindingsDataCache = new WeakMap();
@@ -65,9 +64,8 @@ const bindAttachMethods = function(node, bindDingData, data) {
65
64
 
66
65
 
67
66
  const applyBindingTreePath = (root, target, data, path) => {
68
- let newTarget = null;
69
67
  if(path.fn) {
70
- newTarget = path.fn(data, target, root);
68
+ path.fn(data, target, root);
71
69
  }
72
70
  if(path.children) {
73
71
  for(let i = 0, length = path.children.length; i < length; i++) {
@@ -76,7 +74,6 @@ const applyBindingTreePath = (root, target, data, path) => {
76
74
  applyBindingTreePath(root, pathTargetNode, data, currentPath);
77
75
  }
78
76
  }
79
- return newTarget;
80
77
  };
81
78
 
82
79
  export function TemplateCloner($fn) {
@@ -92,15 +89,10 @@ export function TemplateCloner($fn) {
92
89
  const bindDingData = cloneBindingsDataCache.get(node);
93
90
  if(node.nodeType === 3) {
94
91
  if(bindDingData && bindDingData.value) {
95
- currentPath.fn = (data, targetNode, currentRoot) => {
96
- const newNode = bindDingData.value(data);
97
- if (targetNode === currentRoot) {
98
- return newNode;
99
- }
100
- targetNode.replaceWith(newNode);
101
- return null;
102
- };
103
- return bindDingData.value(data);
92
+ currentPath.fn = bindDingData.value;
93
+ const textNode = node.cloneNode();
94
+ bindDingData.value(data, textNode);
95
+ return textNode;
104
96
  }
105
97
  return node.cloneNode(true);
106
98
  }
@@ -137,11 +129,7 @@ export function TemplateCloner($fn) {
137
129
  const cloneWithBindingPaths = (data) => {
138
130
  let root = $node.cloneNode(true);
139
131
 
140
- const newRoot = applyBindingTreePath(root, root, data, $bindingTreePath);
141
- if(newRoot) {
142
- root = newRoot;
143
- }
144
-
132
+ applyBindingTreePath(root, root, data, $bindingTreePath);
145
133
  return root;
146
134
  };
147
135
 
@@ -176,13 +164,13 @@ export function TemplateCloner($fn) {
176
164
  }
177
165
  this.value = (callbackOrProperty) => {
178
166
  if(typeof callbackOrProperty !== 'function') {
179
- return createBinding(function(data) {
167
+ return createBinding(function(data, textNode) {
180
168
  const firstArgument = data[0];
181
- return createTextNode(firstArgument[callbackOrProperty]);
169
+ ElementCreator.bindTextNode(textNode, firstArgument[callbackOrProperty]);
182
170
  }, 'value');
183
171
  }
184
- return createBinding(function(data) {
185
- return createTextNode(callbackOrProperty(...data));
172
+ return createBinding(function(data, textNode) {
173
+ ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
186
174
  }, 'value');
187
175
  };
188
176
  this.attr = (fn) => {