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