import { SimpleEmitter } from "./SimpleEmitter"; import { WritableProperty } from "./WritableProperty"; import { SimpleProperty } from "./SimpleProperty"; import { Emitter } from "./Emitter"; import { Property } from "./Property"; import { DependentProperty } from "./DependentProperty"; import { WritableArrayProperty } from "./WritableArrayProperty"; import { SimpleWritableArrayProperty } from "./SimpleWritableArrayProperty"; export function emitter(): Emitter { return new SimpleEmitter(); } export function property(value: T): WritableProperty { return new SimpleProperty(value); } export function array_property(...values: T[]): WritableArrayProperty { return new SimpleWritableArrayProperty(...values); } export function if_defined( property: Property, f: (value: S) => T, default_value: T, ): T { const val = property.val; return val == undefined ? default_value : f(val); } export function add(left: Property, right: number): Property { return left.map(l => l + right); } export function sub(left: Property, right: number): Property { return left.map(l => l - right); } export function map( f: (prop_1: S, prop_2: T) => R, prop_1: Property, prop_2: Property, ): Property { return new DependentProperty([prop_1, prop_2], () => f(prop_1.val, prop_2.val)); }