ORDINARY TYPESCRIPT. REAL COMPOSITION.
One value.
Every place it belongs.
A RefSubject is current state and a stream of changes. Derive the total, interpolate both values, and give the button an Effect. The renderer connects the updates and owns their subscriptions.
Understand the example →import { RefSubject } from "@typed/fx";
import { component, html } from "@typed/template";
import { Button } from "@typed/ui/Button";
export const Quantity = component(function* () {
const quantity = yield* RefSubject.make(1);
const total = RefSubject.map(quantity, n => n * 24);
return html`<section>
<output>${quantity} items · $${total}</output>
${Button({
content: "Add an item",
onclick: RefSubject.increment(quantity),
})}
</section>`;
});