import { DynamicValue, Listener, Unsubscriber } from "./DynamicValue" /** * A [[DynamicValue]] reducer returning the truthiness of the input * * @example * ```javascript * new BooleanizedValue(new TextValue("")).onValue(value=> * value //false * ) * ``` */ export class BooleanizedValue implements DynamicValue { __variant__="BooleanizedValue" input:DynamicValue name:string|void constructor(input:DynamicValue,name?:string){ this.input = input this.name = name } onValue(listener:Listener):Unsubscriber{ const unsubscribe = this.input.onValue(val=> { listener(!!val) }) return ()=> { unsubscribe() } } async getValue(){ return !!await this.input.getValue() } static fromJSON(json: { input: any, name?:string }){ return new BooleanizedValue(DynamicValue.fromJSON(json.input),json.name) } }