native-document 1.0.36 → 1.0.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -37,6 +37,23 @@ const bindAttributes = (node, bindDingData, data) => {
37
37
  return null;
38
38
  };
39
39
 
40
+ const $hydrateFn = function(hydrateFunction, target, element, property) {
41
+ if(!cloneBindingsDataCache.has(element)) {
42
+ // { classes, styles, attributes, value, attach }
43
+ cloneBindingsDataCache.set(element, {});
44
+ }
45
+ const hydrationState = cloneBindingsDataCache.get(element);
46
+ if(target === 'value') {
47
+ hydrationState.value = hydrateFunction;
48
+ return;
49
+ }
50
+ if(target === 'attach') {
51
+ hydrationState.attach = hydrateFunction;
52
+ return;
53
+ }
54
+ hydrationState[target] = hydrationState[target] || {};
55
+ hydrationState[target][property] = hydrateFunction;
56
+ }
40
57
 
41
58
  const bindAttachMethods = function(node, bindDingData, data) {
42
59
  if(!bindDingData.attach) {
@@ -47,6 +64,7 @@ const bindAttachMethods = function(node, bindDingData, data) {
47
64
 
48
65
  export function TemplateCloner($fn) {
49
66
  let $node = null;
67
+ let $hasBindingData = false;
50
68
 
51
69
  const clone = (node, data) => {
52
70
  const bindDingData = cloneBindingsDataCache.get(node);
@@ -56,11 +74,14 @@ export function TemplateCloner($fn) {
56
74
  }
57
75
  return node.cloneNode(true);
58
76
  }
59
- const nodeCloned = node.cloneNode();
77
+ const nodeCloned = node.cloneNode(node.fullCloneNode);
60
78
  if(bindDingData) {
61
79
  bindAttributes(nodeCloned, bindDingData, data);
62
80
  bindAttachMethods(nodeCloned, bindDingData, data);
63
81
  }
82
+ if(node.fullCloneNode) {
83
+ return nodeCloned;
84
+ }
64
85
  const childNodes = node.childNodes;
65
86
  for(let i = 0, length = childNodes.length; i < length; i++) {
66
87
  const childNode = childNodes[i];
@@ -73,31 +94,25 @@ export function TemplateCloner($fn) {
73
94
  this.clone = (data) => {
74
95
  if(!$node) {
75
96
  $node = $fn(this);
97
+ if(!$hasBindingData) {
98
+ const nodeCloned = $node.cloneNode(true);
99
+ nodeCloned.fullCloneNode = true;
100
+ return nodeCloned;
101
+ }
102
+ }
103
+ if(!$hasBindingData) {
104
+ return $node.cloneNode(true);
76
105
  }
77
106
  return clone($node, data);
78
107
  };
79
108
 
80
- const $hydrateFn = function(hydrateFunction, target, element, property) {
81
- if(!cloneBindingsDataCache.has(element)) {
82
- // { classes, styles, attributes, value, attach }
83
- cloneBindingsDataCache.set(element, {});
84
- }
85
- const hydrationState = cloneBindingsDataCache.get(element);
86
- if(target === 'value') {
87
- hydrationState.value = hydrateFunction;
88
- return;
89
- }
90
- if(target === 'attach') {
91
- hydrationState.attach = hydrateFunction;
92
- return;
93
- }
94
- hydrationState[target] = hydrationState[target] || {};
95
- hydrationState[target][property] = hydrateFunction;
96
- }
97
109
 
98
110
  const createBinding = (hydrateFunction, target) => {
99
111
  return {
100
- $hydrate : (element, property) => $hydrateFn(hydrateFunction, target, element, property),
112
+ $hydrate : (element, property) => {
113
+ $hasBindingData = true;
114
+ $hydrateFn(hydrateFunction, target, element, property)
115
+ },
101
116
  }
102
117
  };
103
118
 
@@ -147,4 +162,4 @@ export function useCache(fn) {
147
162
  return function(_, __, ...args) {
148
163
  return wrapper([_, __, ...args]);
149
164
  };
150
- }
165
+ }