interface Reactive{ readonly value: T; update: () => Promise; wireTo(...r: Reactive[]): void; unwireTo(r: Reactive): void; } export async function createReactive(fn: () => Promise): Promise> { let v = await fn(); let listeners: Reactive[] = []; return { get value() : T { return v; }, async update(){ const ret = await fn(); v = ret; await Promise.all(listeners.map(o => o.update())); }, wireTo(...r: Reactive[]) { listeners.push(...r); }, unwireTo(r: Reactive) { listeners = listeners.filter(o => o !== r); } }; }