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