mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* ⚡ 🎉 * ⚡ wip * 🔤 * ⚡ wip * ⚡ wip * ⚡ Refatc signals to .get/.set syntax #26 * 🐛 Better types for on* * 🔤 * 🔤 * 🐛 coumputed signal * 🔤 ⚡ Docs UI/UX * ⚡ 🔤 UI enhancements * ⚡ (bs) (un)min * 🔤 adds debugging * 🔤 ssr * 🔤 * ⚡ bs/lint * 🔤 * 🔤 UI * 🔤 updates texts * 🔤UI * ⚡ dispatch * 🔤 events * 🔤 elements * 🔤 intro * 🐛 fixes completitions for el with components * 🐛 wrong file(s) in git * 🔤 logo * 🐛 🔤 types 3ps * 🔤 ui/ux * 🔤 * 🔤 * 🔤 scopes * 🔤 * 🔤 ui/ux * 🔤 * ⚡ issignal * 🔤 improvemens * ⚡ irelands * 🔤 UI/UX/wording * 🐛 npx-hint [Scrollable region must have keyboard access | Axe Rules | Deque University | Deque Systems](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable?application=axeAPI) * 🔤 logos * ⚡ better? dts builds * Update README.md
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import { style, el, S, isSignal } from '../exports.js';
|
|
const className= style.host(thirdParty).css`
|
|
:host {
|
|
color: green;
|
|
}
|
|
`;
|
|
|
|
const store_adapter= {
|
|
read(){ return (new URL(location)).searchParams; },
|
|
write(data){ console.log(data); history.replaceState("", "", "?"+(new URLSearchParams(data)).toString()); }
|
|
};
|
|
export function thirdParty(){
|
|
const store= S({
|
|
value: S("initial")
|
|
}, {
|
|
set(key, value){
|
|
const p= this.value[key] || S();
|
|
p.set(value);
|
|
this.value[key]= p;
|
|
}
|
|
});
|
|
// Array.from((new URL(location)).searchParams.entries())
|
|
// .forEach(([ key, value ])=> S.action(store, "set", key, value));
|
|
// S.on(store, data=> history.replaceState("", "",
|
|
// "?"+(new URLSearchParams(JSON.parse(JSON.stringify(data)))).toString()));
|
|
useStore(store_adapter, {
|
|
onread(data){
|
|
Array.from(data.entries())
|
|
.forEach(([ key, value ])=> S.action(store, "set", key, value));
|
|
return store;
|
|
}
|
|
})();
|
|
return el("input", {
|
|
className,
|
|
value: store.get().value.get(),
|
|
type: "text",
|
|
onchange: ev=> S.action(store, "set", "value", ev.target.value)
|
|
});
|
|
}
|
|
|
|
function useStore(adapter_in, { onread, onbeforewrite }= {}){
|
|
const adapter= typeof adapter_in === "function" ? { read: adapter_in } : adapter_in;
|
|
if(!onread) onread= S;
|
|
if(!onbeforewrite) onbeforewrite= data=> JSON.parse(JSON.stringify(data));
|
|
return function useStoreInner(data_read){
|
|
const signal= onread(adapter.read(data_read)); //TODO OK as synchronous
|
|
if(adapter.write && isSignal(signal))
|
|
S.on(signal, data=> adapter.write(onbeforewrite(data)));
|
|
return signal;
|
|
};
|
|
}
|