Compare commits
No commits in common. "26cb46923fead330d205950a7b3ac06707c159e7" and "7847410f3e6c624bc3461312681b9afb382c7010" have entirely different histories.
26cb46923f
...
7847410f3e
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Launch Program",
|
|
||||||
"type": "node",
|
|
||||||
"program": "${workspaceFolder}/server.tsx",
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"runtimeExecutable": "C:\\Users\\Seth\\.deno\\bin\\deno.EXE",
|
|
||||||
"runtimeArgs": [
|
|
||||||
"run",
|
|
||||||
"--no-lock",
|
|
||||||
"--unstable",
|
|
||||||
"--inspect-wait",
|
|
||||||
"--allow-all"
|
|
||||||
],
|
|
||||||
"attachSimplePort": 9229
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -10,13 +10,13 @@ const delay =async(inHandler:()=>void, inDelay:number):Promise<void>=>
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const queue = [1, 2, 3];
|
const cacheRecord = {Promise:delay(()=>{}, 1000)};
|
||||||
while(queue.length)
|
|
||||||
{
|
cacheRecord.Promise.then(()=>{console.log(`handler one`)});
|
||||||
await(delay(()=>{console.log(queue.pop())}, 1000))
|
cacheRecord.Promise.then(()=>{console.log(`handler two`)});
|
||||||
}
|
|
||||||
|
cacheRecord.Promise = delay(()=>{}, 3000);
|
||||||
|
|
||||||
console.log("all done!");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let r1, r2, r3;
|
let r1, r2, r3;
|
||||||
|
42
lib/iso.tsx
42
lib/iso.tsx
@ -160,19 +160,10 @@ export const Switch =({children}:{children:Children})=>
|
|||||||
export const Case =({children, value}:{children:Children, value?:string, default?:true})=>null;
|
export const Case =({children, value}:{children:Children, value?:string, default?:true})=>null;
|
||||||
export const useRouteVars =()=> React.useContext(SwitchContext).keys;
|
export const useRouteVars =()=> React.useContext(SwitchContext).keys;
|
||||||
|
|
||||||
export type FetchRecord = {URL:string, CacheFor:number, CachedAt:number, CacheOnServer:boolean, Promise?:Promise<FetchRecord>, DelaySSR:boolean, Error?:string, JSON?:object};
|
type FetchRecord = {URL:string, CacheFor:number, CachedAt:number, Promise?:Promise<FetchRecord>, DelaySSR:boolean, Error?:string, JSON?:object};
|
||||||
export const Fetch = {
|
export const Fetch = {
|
||||||
Cache:new Map() as Map<string, FetchRecord>,
|
Cache:new Map() as Map<string, FetchRecord>,
|
||||||
ServerBlocking:false as false|Promise<FetchRecord>[],
|
Request(URL:string, Init?:RequestInit, CacheFor:number = 60, DelaySSR:boolean = true)
|
||||||
ServerTouched:new Set() as Set<FetchRecord>,
|
|
||||||
Seed(seed:FetchRecord[])
|
|
||||||
{
|
|
||||||
seed.forEach(r=>{
|
|
||||||
r.Promise = Promise.resolve(r);
|
|
||||||
Fetch.Cache.set(r.URL, r)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
Request(URL:string, Init?:RequestInit, CacheFor:number = 60, CacheOnServer:boolean = true, DelaySSR:boolean = true)
|
|
||||||
{
|
{
|
||||||
let check = Fetch.Cache.get(URL);
|
let check = Fetch.Cache.get(URL);
|
||||||
|
|
||||||
@ -192,7 +183,7 @@ export const Fetch = {
|
|||||||
if(!check)
|
if(!check)
|
||||||
{
|
{
|
||||||
console.log(`making new cache record...`);
|
console.log(`making new cache record...`);
|
||||||
return load({URL, CacheFor, CachedAt:0, CacheOnServer, DelaySSR});
|
return load({URL, CacheFor, CachedAt:0, DelaySSR});
|
||||||
}
|
}
|
||||||
else if(check.CachedAt == 0)
|
else if(check.CachedAt == 0)
|
||||||
{
|
{
|
||||||
@ -216,30 +207,23 @@ export const Fetch = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Use(URL:string, Init?:RequestInit, CacheFor:number = 60, CacheOnServer:boolean = true, DelaySSR:boolean = true)
|
Use(URL:string, Init?:RequestInit, CacheFor:number = 60, DelaySSR:boolean = true)
|
||||||
{
|
{
|
||||||
type FetchHookState = [Data:undefined|object, Updating:boolean];
|
type FetchHookState = [Data:undefined|object, Updating:boolean];
|
||||||
const [cacheGet, cacheSet] = React.useState([undefined, true] as FetchHookState);
|
const [cacheGet, cacheSet] = React.useState([undefined, true] as FetchHookState);
|
||||||
if(Fetch.ServerBlocking && DelaySSR)
|
|
||||||
{
|
|
||||||
const receipt = Fetch.Request(URL, Init, CacheFor, CacheOnServer, DelaySSR);
|
|
||||||
if(receipt.CachedAt === 0 && receipt.Promise)
|
|
||||||
{
|
|
||||||
Fetch.ServerBlocking.push(receipt.Promise);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Fetch.ServerTouched.add(receipt);
|
|
||||||
}
|
|
||||||
return [receipt.JSON, receipt.CachedAt === 0];
|
|
||||||
}
|
|
||||||
React.useEffect(()=>
|
React.useEffect(()=>
|
||||||
{
|
{
|
||||||
const receipt = Fetch.Request(URL, Init, CacheFor, CacheOnServer, DelaySSR);
|
const receipt = Fetch.Request(URL, Init, CacheFor, DelaySSR);
|
||||||
receipt.Promise?.then(()=>cacheSet([receipt.JSON, receipt.CachedAt === 0]));
|
receipt.Promise?.then(()=>{
|
||||||
|
++count;
|
||||||
|
if(count > 10){return;}
|
||||||
|
console.log(`updating state`, receipt);
|
||||||
|
cacheSet([receipt.JSON, receipt.CachedAt === 0]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
, []);
|
, []);
|
||||||
|
|
||||||
return cacheGet;
|
return cacheGet;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let count = 0;
|
26
server.tsx
26
server.tsx
@ -221,29 +221,10 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Iso.Fetch.ServerBlocking = [];
|
const results = Twind.extract(SSR(<Iso.Router.Provider url={url}><App/></Iso.Router.Provider>), TwindInst);
|
||||||
let bake = SSR(<Iso.Router.Provider url={url}><App/></Iso.Router.Provider>);
|
|
||||||
while(Iso.Fetch.ServerBlocking.length)
|
|
||||||
{
|
|
||||||
await Promise.all(Iso.Fetch.ServerBlocking);
|
|
||||||
Iso.Fetch.ServerBlocking = [];
|
|
||||||
bake = SSR(<Iso.Router.Provider url={url}><App/></Iso.Router.Provider>);
|
|
||||||
}
|
|
||||||
|
|
||||||
const seed:Iso.FetchRecord[] = [];
|
|
||||||
Iso.Fetch.ServerTouched.forEach((record)=>{
|
|
||||||
|
|
||||||
const r:Iso.FetchRecord = {...record};
|
|
||||||
delete r.Promise;
|
|
||||||
seed.push(r);
|
|
||||||
});
|
|
||||||
Iso.Fetch.ServerTouched = new Set();
|
|
||||||
|
|
||||||
const results = Twind.extract(bake, TwindInst);
|
|
||||||
|
|
||||||
type = `text/html`;
|
type = `text/html`;
|
||||||
body =
|
body = `<!doctype html>
|
||||||
`<!doctype html>
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>${Iso.Meta.title}</title>
|
<title>${Iso.Meta.title}</title>
|
||||||
@ -258,9 +239,8 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
import {render, createElement as H} from "react";
|
import {render, createElement as H} from "react";
|
||||||
import * as Twind from "https://esm.sh/v115/@twind/core@1.1.3/es2022/core.mjs";
|
import * as Twind from "https://esm.sh/v115/@twind/core@1.1.3/es2022/core.mjs";
|
||||||
import {default as App, CSS} from "@eno/app";
|
import {default as App, CSS} from "@eno/app";
|
||||||
import {Router, Fetch} from "@eno/iso";
|
import {Router} from "@eno/iso";
|
||||||
Twind.install(CSS);
|
Twind.install(CSS);
|
||||||
Fetch.Seed(${JSON.stringify(seed)});
|
|
||||||
render( H(Router.Provider, null, H(App)), document.querySelector("#app"));
|
render( H(Router.Provider, null, H(App)), document.querySelector("#app"));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user