Compare commits

..

No commits in common. "fafdeffeebc578a0013dcbba58121f91fd5fd42c" and "8ab67be4d8adc60e0c9db55d803a309ac78b8867" have entirely different histories.

4 changed files with 37 additions and 56 deletions

View File

@ -8,7 +8,7 @@ const Comp = React.lazy(()=>import("./deep/component.tsx"));
export default ()=>
{
return <div class="p-4 font-sans">
<Iso.Meta.Metas title="Main Page!"/>
<Iso.Metas title="Main Page!"/>
<nav class="p-4">
<a class="text-red-500" href="/">Home</a>
<a href="/about">About</a>

View File

@ -13,7 +13,7 @@ export default ()=>
console.log("render!!")
return <div class="p-4 text-red-500">
<Iso.Meta.Metas title="Component!"/>
<Iso.Metas title="Component!"/>
Component Route is: {routeGet.Path.toString()}
<button className="p-4 bg-green-500 text-white" onClick={e=>{countSet(countGet+1); routeSet(["lol", "idk"], {count:countGet+1});}}>{countGet}</button>
<a href="/page/about-us" className="p-2 text(lg blue-500) font-bold">a link</a>

View File

@ -1,28 +1,20 @@
import React from "react";
type MetasInputs = { [Property in MetaKeys]?: string };
type Meta = {title:string, description:string, keywords:string, image:string, canonical:string }
type MetaKeys = keyof Meta;
export const Meta =
{
Meta: {
export const Meta:Meta = {
title:"",
description:"",
keywords:"",
image:"",
canonical:""
} as Meta,
Context: React.createContext([{} as Meta, ()=>{}] as [Get:Meta, Set:React.StateUpdater<Meta>]),
Provider({children}:{children:Children})
{
const binding = React.useState(Meta.Meta);
return <Meta.Context.Provider value={binding}>{children}</Meta.Context.Provider>;
},
Metas(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null
{
const additive = props.concatListed ? (key:MetaKeys, value:string)=> Meta.Meta[key] += value : (key:MetaKeys, value:string)=> Meta.Meta[key] = value;
const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta.Meta[key] = "" : (key:MetaKeys)=> {};
};
type MetasInputs = { [Property in MetaKeys]?: string };
export const Metas =(props:{concatListed?:boolean; dropUnlisted?:boolean}&MetasInputs):null=>
{
const additive = props.concatListed ? (key:MetaKeys, value:string)=> Meta[key] += value : (key:MetaKeys, value:string)=> Meta[key] = value;
const subtractive = props.dropUnlisted ? (key:MetaKeys)=> Meta[key] = "" : (key:MetaKeys)=> {};
Object.keys(Meta).forEach((key)=>{
const metaKey = key as MetaKeys;
@ -31,12 +23,11 @@ export const Meta =
})
if(window.innerWidth)
{
document.title = Meta.Meta.title;
document.title = Meta.title;
}
return null;
}
};
}
export type Children = string | number | React.JSX.Element | React.JSX.Element[];
@ -87,10 +78,7 @@ export const Router = {
document.addEventListener("click", e=>
{
const t = e.target as HTMLAnchorElement;
const path = e.composedPath() as HTMLAnchorElement[];
for(let i=0; i<path.length; i++)
{
if(path[i].href)
if(t.href)
{
const u = new URL(t.href);
if(u.origin == document.location.origin)
@ -99,8 +87,6 @@ export const Router = {
const parts = Router.Parse(u);
routeUpdate(parts.Path, parts.Params, parts.Anchor);
}
return;
}
}
})
}, []);

View File

@ -226,7 +226,7 @@ FileListen("${url.pathname}", reloadHandler);`;
Iso.Fetch.ServerBlocking = [];
Iso.Fetch.ServerTouched = new Set();
Iso.Fetch.ServerRemove = new Set();
let app = <Iso.Router.Provider url={url}><Iso.Meta.Provider><App/></Iso.Meta.Provider></Iso.Router.Provider>;
let app = <Iso.Router.Provider url={url}><App/></Iso.Router.Provider>;
await Prepass(app)
let bake = SSR(app);
while(Iso.Fetch.ServerBlocking.length)
@ -235,7 +235,7 @@ FileListen("${url.pathname}", reloadHandler);`;
Iso.Fetch.ServerBlocking = [];
// at this point, anything that was requested that was not cached, has now been loaded and cached
// this next render will use cached resources. using a cached resource (if its "Seed" is true) adds it to the "touched" set.
app = <Iso.Router.Provider url={url}><Iso.Meta.Provider><App/></Iso.Meta.Provider></Iso.Router.Provider>;
app = <Iso.Router.Provider url={url}><App/></Iso.Router.Provider>;
await Prepass(app)
bake = SSR(app);
}
@ -255,7 +255,7 @@ FileListen("${url.pathname}", reloadHandler);`;
`<!doctype html>
<html lang="en">
<head>
<title>${Iso.Meta.Meta.title}</title>
<title>${Iso.Meta.title}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"/>
<style data-twind>${results.css}</style>
@ -271,12 +271,7 @@ FileListen("${url.pathname}", reloadHandler);`;
Twind.install(CSS);
Fetch.Seed(${JSON.stringify(seed)});
const hmrWrap = H( ()=>H(App) );
hydrate(
H(Router.Provider, null,
H(Meta.Provider, null, hmrWrap)
),
document.querySelector("#app")
);
hydrate( H(Router.Provider, null, hmrWrap), document.querySelector("#app"));
</script>
</body>
</html>`;