Added fire property to sub method of state

This commit is contained in:
Kevand
2026-04-09 02:22:31 +01:00
parent 91015c46fd
commit 3ac3331070

View File

@@ -28,9 +28,13 @@ export function createState<T>(initial: T): State<T> {
subs.forEach((s) => s()); subs.forEach((s) => s());
} }
function sub(fn: Listener) { function sub(fn: Listener, fire = false) {
subs.push(fn); subs.push(fn);
if (fire) {
fn();
}
return () => { return () => {
const idx = subs.indexOf(fn); const idx = subs.indexOf(fn);
if (idx > -1) { if (idx > -1) {