hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
react global store and reducer seem like anitpatterns. one is just a global variable another is defining businose logic in some weird reducer store instead of using normal class with methods inside state wrapper
- Assistant
- User
no im buuilding my own react and im think if should even bother adding these. I just have Signal and Store thing with sub and set methods the render function subscribes to them and u trigger it with set which passes contained value
- Assistant
- User
i mean u can already use store as a global store. the difference between it and signal is that signal only allows for 1 subscriber and has trigger method and store allows for multiple subscribers with id key
- Assistant
Thanks for clarifying! So your design distinguishes:
- User
this is the render core btw its not finished, im gonna use deps array to add diffing/memoisation type FC<P extends Record<string, unknown>> = (props: P) => HTMLElement | void;
interface Observable { sub(f: (...a: unknown[]) => unknown, id?: string): unknown; }
interface Executable { ex(...a: unknown[]): unknown; }
interface Applicative { ap(...a: unknown[]): unknown; }
interface Setter { set(f: (...a: unknown[]) => unknown): unknown; }
const check = (x: any, f: string) => f in x && typeof x[f] === "function";
const Render = ( thunk: () => HTMLElement | void, hooks?: (Observable | Executable | Applicative | Setter)[], id?: string, deps?: unknown[], ): HTMLElement | void => { let el = thunk();
const observables = hooks?.filter((x) => check(x, "sub")) as Observable[]; const executables = hooks?.filter((x) => check(x, "ex")) as Executable[]; const applicatives = hooks?.filter((x) => check(x, "ap")) as Applicative[]; const setters = hooks?.filter((x) => check(x, "sub") ? false : check(x, "set"), ) as Setter[];
- Assistant
- User
they use map for sub id and when id isnt provided they use callback string content
- Assistant
- User
this is how it works. im building a devtools widget with it in a floatign window with console and tools views import { FC, Render, Root, Signal, Reader, IO, Memo, Cleanup, } from "../../lib/index"; import { Window } from "./Window"; import { Console } from "./Console"; import { Tools } from "./Tools";
interface Settings { mode: "console" | "tools"; }
const defaultSettings: Settings = { mode: "console" };
const loadSettings = Reader( (id: string) => ({ mode: localStorage.getItem(
${id}: mode) ?? "console", }) as Settings, );const saveSettings = IO((id: string, mode: Signal<"console" | "tools">) => { localStorage.setItem(
${id}: mode, mode.ref()); });const initConsole = Reader((logs: any[]) => { console.log = (...things: any[]) => things.forEach((x) => logs.push(x)); });
const DevTools: FC<{ id: string }> = ({ id }) => { const settings = loadSettings.ex(id).alt(defaultSettings); const mode = Signal(settings.mode); const rerender = Signal(0); const logs: any[] = [];
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.