import { Signal } from "@preact-signals/unified-signals"; import { Setter } from "./type"; function setter(this: Signal, value: Setter) { const currentValue = this.peek(); // @ts-expect-error unions const newValue = typeof value === "function" ? value(currentValue) : value; this.value = newValue; return newValue; } export const setterOfSignal = (signal: Signal): Setter => setter.bind(signal) as Setter; export const toggleSignal = (sig: Signal) => { sig.value = !sig.peek(); };