@daz4126/helium 0.7.1 → 0.7.3

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 +20 -20
  2. package/package.json +1 -1
package/helium.js CHANGED
@@ -16,26 +16,24 @@ export default function helium(data = {}) {
16
16
  return temp.content.firstChild;
17
17
  };
18
18
 
19
- const ajax = (url, method, target, options) => {
20
- fetch(url, {
21
- method,
19
+ const ajax = (m, u, t, d) =>
20
+ fetch(u, {
21
+ method: m,
22
22
  headers: { "Content-Type": "application/json" },
23
- body: method === "GET" ? null : JSON.stringify(options),
23
+ body: m == "GET" ? null : JSON.stringify(d),
24
24
  })
25
- .then((res) =>
26
- res.headers.get("content-type")?.includes("application/json")
27
- ? res.json()
28
- : res.text(),
25
+ .then((r) =>
26
+ r[r.headers.get("content-type")?.includes("json") ? "json" : "text"](),
29
27
  )
30
- .then((data) => {
31
- state[target] = data;
32
- });
33
- };
34
- const get = (url, prop) => ajax(url, "GET", prop);
35
- const post = (url, params, prop) => ajax(url, "POST", prop, params);
36
- const put = (url, params, prop) => ajax(url, "PUT", prop, params);
37
- const patch = (url, params, prop) => ajax(url, "PATCH", prop, params);
38
- const del = (url, params, prop) => ajax(url, "DELETE", prop, params);
28
+ .then((x) => (state[t] = x));
29
+
30
+ const [get, post, put, patch, del] = [
31
+ "GET",
32
+ "POST",
33
+ "PUT",
34
+ "PATCH",
35
+ "DELETE",
36
+ ].map((m) => (u, d, t) => ajax(m, u, t, d));
39
37
 
40
38
  const state = new Proxy(data, {
41
39
  get(target, prop) {
@@ -142,6 +140,8 @@ export default function helium(data = {}) {
142
140
  heliumElements.forEach((el) => {
143
141
  for (const { name, value } of el.attributes || []) {
144
142
  if (
143
+ name == "@html" ||
144
+ name == "data-he-html" ||
145
145
  name == "@text" ||
146
146
  name == "data-he-text" ||
147
147
  name == "@bind" ||
@@ -150,9 +150,9 @@ export default function helium(data = {}) {
150
150
  try {
151
151
  new Function(`let ${value} = 1`);
152
152
  state[value] ||=
153
- name == "@text" || name == "data-he-text"
154
- ? el.textContent
155
- : el.value;
153
+ name == "@bind" || name == "data-he-bind"
154
+ ? el.value
155
+ : el.textContent;
156
156
  } catch (e) {}
157
157
  }
158
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/helium",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "main": "helium.js",
5
5
  "type": "module",
6
6
  "keywords": [