This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { $, watch, batch, h, Fragment, mount, when, each, onUnmount, isArr, isFunc, isObj } from "./sigpro.js"
|
||||
import { router } from "./router.js"
|
||||
import { db } from "./utils.js"
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
Object.assign(window, { $, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj })
|
||||
Object.assign(window, { $, watch, h, Fragment, when, each, router, mount, batch, onUnmount, isArr, isFunc, isObj, db })
|
||||
}
|
||||
23
src/utils.js
Normal file
23
src/utils.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// utils.js
|
||||
|
||||
export const db = async (url, data = {}, loading = null) => {
|
||||
if (loading) loading(true);
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text();
|
||||
throw new Error(`Error ${res.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
|
||||
} finally {
|
||||
if (loading) loading(false);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user