diff --git a/dev_server.ts b/dev_server.ts index 4250307..0f426c2 100644 --- a/dev_server.ts +++ b/dev_server.ts @@ -3,32 +3,22 @@ import { contentType } from "jsr:@std/media-types"; // Parse the port from the command-line arguments, defaulting to 8000 const port = parseInt(Deno.args[0] || "8000", 10); const sockets: WebSocket[] = []; -const connect = ``; - const bundle = await fetch(import.meta.resolve("./bundle.js")).then(r=>r.text()); +const devinc = await fetch(import.meta.resolve("./src/dev.js")).then(r=>r.text()); let html: string; try { - html = Deno.readTextFileSync("./index.html").replace("
", ""+connect); + html = Deno.readTextFileSync("./index.html").replace("", ``); } catch (_) { html = ` - ${connect} + `; diff --git a/src/dev.js b/src/dev.js new file mode 100644 index 0000000..c228d00 --- /dev/null +++ b/src/dev.js @@ -0,0 +1,32 @@ +// added in devmode to index.html +new WebSocket('ws://'+window.location.host+'/ws').addEventListener('message',e=>e.data==='reload'&&window.location.reload()); + +vanX.Store =(obj, key)=> +{ + let checkInit = JSON.stringify(obj); + let checkStore = localStorage.getItem(key+"check"); + localStorage.setItem(key+"check", checkInit); + + let recallJSON; + if(checkInit == checkStore) + { + let recallText = localStorage.getItem(key); + try + { + recallJSON = JSON.parse(recallText) || obj; + } + catch(e) + { + recallJSON = obj; + } + } + else + { + + recallJSON = obj; + } + + const store = vanX.reactive( recallJSON ); + van.derive(() => localStorage.setItem(key, JSON.stringify(vanX.compact(store)))); + return store; +} \ No newline at end of file