@daz4126/helium 0.6.1 → 0.7.1

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