@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.
- package/helium.js +19 -18
- 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 = (
|
|
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(
|
|
23
|
+
body: method === "GET" ? null : JSON.stringify(data),
|
|
25
24
|
})
|
|
26
25
|
.then((res) =>
|
|
27
|
-
res
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
res[
|
|
27
|
+
res.headers.get("content-type")?.includes("json") ? "json" : "text"
|
|
28
|
+
](),
|
|
30
29
|
)
|
|
31
|
-
.then((
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const get = (
|
|
36
|
-
const post = (
|
|
37
|
-
const put = (
|
|
38
|
-
const patch = (
|
|
39
|
-
const del = (
|
|
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 == "@
|
|
155
|
-
? el.
|
|
156
|
-
: el.
|
|
155
|
+
name == "@bind" || name == "data-he-bind"
|
|
156
|
+
? el.value
|
|
157
|
+
: el.textContent;
|
|
157
158
|
} catch (e) {}
|
|
158
159
|
}
|
|
159
160
|
}
|