@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.
- package/helium.js +20 -20
- 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 = (
|
|
20
|
-
fetch(
|
|
21
|
-
method,
|
|
19
|
+
const ajax = (m, u, t, d) =>
|
|
20
|
+
fetch(u, {
|
|
21
|
+
method: m,
|
|
22
22
|
headers: { "Content-Type": "application/json" },
|
|
23
|
-
body:
|
|
23
|
+
body: m == "GET" ? null : JSON.stringify(d),
|
|
24
24
|
})
|
|
25
|
-
.then((
|
|
26
|
-
|
|
27
|
-
? res.json()
|
|
28
|
-
: res.text(),
|
|
25
|
+
.then((r) =>
|
|
26
|
+
r[r.headers.get("content-type")?.includes("json") ? "json" : "text"](),
|
|
29
27
|
)
|
|
30
|
-
.then((
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 == "@
|
|
154
|
-
? el.
|
|
155
|
-
: el.
|
|
153
|
+
name == "@bind" || name == "data-he-bind"
|
|
154
|
+
? el.value
|
|
155
|
+
: el.textContent;
|
|
156
156
|
} catch (e) {}
|
|
157
157
|
}
|
|
158
158
|
}
|