UNPKG

@lf-lang/reactor-ts

Version:

A reactor-oriented programming framework in TypeScript

30 lines (26 loc) 739 B
import type {Read, Write} from "./internal"; /** * A state variable. This class refines the Read interface by letting `get` * return T rather than T | Absent. If the state should be nullable or * uninitialized, this has to be reflected explicitly in T. */ export class State<T> implements Read<T>, Write<T> { /** * Create a new state variable and assign it an initial value. * @param value The initial value to assign to this state variable. */ constructor(private value: T) {} /** * Return the current value of this state variable. */ get(): T { return this.value; } /** * Set the current value of this state variable. * @param value */ set(value: T): void { this.value = value; } }