@daz4126/helium 0.6.1 → 0.7.0
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/helium.js +19 -4
- package/package.json +1 -1
package/helium.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let ue = true;
|
|
1
2
|
export default function helium(data = {}) {
|
|
2
3
|
const root =
|
|
3
4
|
document.querySelector("[\\@helium]") ||
|
|
@@ -16,6 +17,7 @@ export default function helium(data = {}) {
|
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
const ajax = (url, method, target, options) => {
|
|
20
|
+
console.log(url, method, target, options);
|
|
19
21
|
fetch(url, {
|
|
20
22
|
method,
|
|
21
23
|
headers: { "Content-Type": "application/json" },
|
|
@@ -26,10 +28,13 @@ export default function helium(data = {}) {
|
|
|
26
28
|
? res.json()
|
|
27
29
|
: res.text(),
|
|
28
30
|
)
|
|
29
|
-
.then((data) =>
|
|
31
|
+
.then((data) => {
|
|
32
|
+
state[target] = data;
|
|
33
|
+
});
|
|
30
34
|
};
|
|
31
35
|
const get = (url, prop) => ajax(url, "GET", prop);
|
|
32
36
|
const post = (url, params, prop) => ajax(url, "POST", prop, params);
|
|
37
|
+
const put = (url, params, prop) => ajax(url, "PUT", prop, params);
|
|
33
38
|
const patch = (url, params, prop) => ajax(url, "PATCH", prop, params);
|
|
34
39
|
const del = (url, params, prop) => ajax(url, "DELETE", prop, params);
|
|
35
40
|
|
|
@@ -61,6 +66,7 @@ export default function helium(data = {}) {
|
|
|
61
66
|
html,
|
|
62
67
|
get,
|
|
63
68
|
post,
|
|
69
|
+
put,
|
|
64
70
|
patch,
|
|
65
71
|
del,
|
|
66
72
|
...Object.values(data),
|
|
@@ -88,6 +94,7 @@ export default function helium(data = {}) {
|
|
|
88
94
|
"$html",
|
|
89
95
|
"$get",
|
|
90
96
|
"$post",
|
|
97
|
+
"$put",
|
|
91
98
|
"$patch",
|
|
92
99
|
"$delete",
|
|
93
100
|
...Object.keys(data),
|
|
@@ -100,7 +107,7 @@ export default function helium(data = {}) {
|
|
|
100
107
|
}
|
|
101
108
|
|
|
102
109
|
// processElements now returns an array of newly-created binding objects
|
|
103
|
-
function processElements(element) {
|
|
110
|
+
function processElements(element, addEvents = ue) {
|
|
104
111
|
const newlyAddedBindings = [];
|
|
105
112
|
|
|
106
113
|
// quick guard: avoid re-processing same node
|
|
@@ -166,6 +173,7 @@ export default function helium(data = {}) {
|
|
|
166
173
|
html,
|
|
167
174
|
get,
|
|
168
175
|
post,
|
|
176
|
+
put,
|
|
169
177
|
patch,
|
|
170
178
|
del,
|
|
171
179
|
...Object.values(data),
|
|
@@ -258,12 +266,16 @@ export default function helium(data = {}) {
|
|
|
258
266
|
html,
|
|
259
267
|
get,
|
|
260
268
|
post,
|
|
269
|
+
put,
|
|
261
270
|
patch,
|
|
262
271
|
del,
|
|
263
272
|
...Object.values(data),
|
|
264
273
|
...[...refs.values()],
|
|
265
274
|
);
|
|
266
|
-
} else if (
|
|
275
|
+
} else if (
|
|
276
|
+
(name.startsWith("@") || name.startsWith("data-he-on")) &&
|
|
277
|
+
addEvents
|
|
278
|
+
) {
|
|
267
279
|
// event handling — keep this as before (register listeners)
|
|
268
280
|
const [eventName, ...modifiers] = name
|
|
269
281
|
.slice(name.startsWith("@") ? 1 : 10)
|
|
@@ -320,6 +332,7 @@ export default function helium(data = {}) {
|
|
|
320
332
|
html,
|
|
321
333
|
get,
|
|
322
334
|
post,
|
|
335
|
+
put,
|
|
323
336
|
patch,
|
|
324
337
|
del,
|
|
325
338
|
...Object.values(data),
|
|
@@ -349,7 +362,7 @@ export default function helium(data = {}) {
|
|
|
349
362
|
node.nodeType === 1 &&
|
|
350
363
|
!node.hasAttribute("data-helium-processed")
|
|
351
364
|
) {
|
|
352
|
-
const newly = processElements(node);
|
|
365
|
+
const newly = processElements(node, false);
|
|
353
366
|
// apply only the bindings we just created for this node
|
|
354
367
|
newly.forEach(applyBinding);
|
|
355
368
|
}
|
|
@@ -360,5 +373,7 @@ export default function helium(data = {}) {
|
|
|
360
373
|
|
|
361
374
|
const initialBindings = processElements(root);
|
|
362
375
|
for (const [key, items] of bindings.entries()) items.forEach(applyBinding);
|
|
376
|
+
ue = false;
|
|
363
377
|
}
|
|
378
|
+
|
|
364
379
|
helium();
|