native-document 1.0.184 → 1.0.185
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.
|
|
3
|
+
"version": "1.0.185",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {ElementCreator} from '../ElementCreator';
|
|
2
2
|
import {createTextNode} from '../HtmlElementWrapper';
|
|
3
3
|
import {NDElement} from '../NDElement';
|
|
4
|
+
import {call} from '@babel/traverse/lib/path/context';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Stores deferred attribute, class, style, and event bindings for a cloneable element.
|
|
@@ -18,6 +19,7 @@ export default function NodeCloner($element) {
|
|
|
18
19
|
this.$attrs = null;
|
|
19
20
|
this.$ndMethods = null;
|
|
20
21
|
this.$content = null;
|
|
22
|
+
this.$uniqueCallbacks= new Map();
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
NodeCloner.prototype.shouldBeHydrate = function() {
|
|
@@ -56,10 +58,28 @@ const buildProperties = (cache, properties, data) => {
|
|
|
56
58
|
};
|
|
57
59
|
|
|
58
60
|
const getPropertyValue = (callbackOrProperty, data) => {
|
|
61
|
+
if(callbackOrProperty?.__$Observable) {
|
|
62
|
+
return callbackOrProperty;
|
|
63
|
+
}
|
|
59
64
|
const value = (typeof callbackOrProperty ==='string') ? data[0][callbackOrProperty] : callbackOrProperty;
|
|
60
65
|
return (typeof value === 'function') ? value.apply(this, data) : value;
|
|
61
66
|
};
|
|
62
67
|
|
|
68
|
+
|
|
69
|
+
const $nodeClonedCallbackData = new WeakMap();
|
|
70
|
+
|
|
71
|
+
const $nodeClonerCallbackCaller = (callback, event) => {
|
|
72
|
+
const data = $nodeClonedCallbackData.get(event.target);
|
|
73
|
+
callback.apply(event.target, [...data, event]);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
NodeCloner.prototype.resolveMethods = function() {
|
|
77
|
+
for(const methodName in this.$ndMethods) {
|
|
78
|
+
const callback = this.$ndMethods[methodName];
|
|
79
|
+
const uniqueCallback = $nodeClonerCallbackCaller.bind(null, callback);
|
|
80
|
+
this.$uniqueCallbacks.set(methodName, uniqueCallback);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
63
83
|
/**
|
|
64
84
|
* Pre-compiles all registered bindings into a sequence of optimised steps.
|
|
65
85
|
* Called once before the first clone operation. Subsequent calls are no-ops.
|
|
@@ -70,21 +90,24 @@ NodeCloner.prototype.resolve = function() {
|
|
|
70
90
|
if(this.$content) {
|
|
71
91
|
return;
|
|
72
92
|
}
|
|
93
|
+
this.resolveMethods();
|
|
73
94
|
const steps = [];
|
|
74
95
|
if(this.$ndMethods) {
|
|
75
96
|
const methods = Object.keys(this.$ndMethods);
|
|
76
97
|
if(methods.length === 1) {
|
|
77
98
|
const methodName = methods[0];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
clonedNode.nd[methodName](
|
|
99
|
+
steps.push((clonedNode) => {
|
|
100
|
+
const uniqueCallback = this.$uniqueCallbacks.get(methodName);
|
|
101
|
+
clonedNode.nd[methodName](uniqueCallback);
|
|
81
102
|
});
|
|
82
103
|
} else {
|
|
83
|
-
steps.push((clonedNode
|
|
104
|
+
steps.push((clonedNode) => {
|
|
84
105
|
const nd = clonedNode.nd;
|
|
85
106
|
for(const methodName in this.$ndMethods) {
|
|
86
|
-
const
|
|
87
|
-
|
|
107
|
+
const uniqueCallback = this.$uniqueCallbacks.get(methodName);
|
|
108
|
+
|
|
109
|
+
// callback.length === 0 ? callback : this.$ndMethods[methodName].bind(clonedNode, ...data)
|
|
110
|
+
nd[methodName](uniqueCallback);
|
|
88
111
|
}
|
|
89
112
|
});
|
|
90
113
|
}
|
|
@@ -146,6 +169,7 @@ NodeCloner.prototype.resolve = function() {
|
|
|
146
169
|
|
|
147
170
|
this.cloneNode = (data) => {
|
|
148
171
|
const clonedNode = $element.cloneNode(false);
|
|
172
|
+
$nodeClonedCallbackData.set(clonedNode, data);
|
|
149
173
|
for(let i = 0; i < stepsCount; i++) {
|
|
150
174
|
steps[i](clonedNode, data);
|
|
151
175
|
}
|
|
@@ -187,11 +211,7 @@ NodeCloner.prototype.attach = function(methodName, callback) {
|
|
|
187
211
|
*/
|
|
188
212
|
NodeCloner.prototype.text = function(valueOrProperty) {
|
|
189
213
|
this.$content = valueOrProperty;
|
|
190
|
-
|
|
191
|
-
this.cloneNode = (data) => createTextNode(valueOrProperty.apply(null, data));
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
this.cloneNode = (data) => createTextNode(data[0][valueOrProperty]);
|
|
214
|
+
this.cloneNode = (data) => createTextNode(getPropertyValue(valueOrProperty, data));
|
|
195
215
|
return this;
|
|
196
216
|
};
|
|
197
217
|
|