@daz4126/helium 0.7.1 → 0.7.2

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