lazy-widgets
Version:
Typescript retained mode GUI for the HTML canvas API
32 lines (31 loc) • 1.35 kB
TypeScript
import { type ValidatedBox } from './ValidatedBox.js';
import { type ValidationResult } from './ValidationResult.js';
import { type Validator } from './Validator.js';
import { Variable } from './Variable.js';
/**
* Similar to {@link Variable}, except the variable's value can optionally be
* validated by a {@link Validator | validator function}.
*
* @typeParam V - The type of {@link Variable#value}.
* @typeParam T - The transformed type of a {@link ValidatedVariable#validValue | valid value}.
*
* @category State Management
*/
export declare class ValidatedVariable<V, T = V> extends Variable<V> implements ValidatedBox<V, T> {
/** See {@link ValidatedVariable#valid}. For internal use only */
private _valid;
/** See {@link ValidatedVariable#validValue}. For internal use only */
private _validValue?;
/**
* The validator/transformer used for this variable's value. If null, then
* the value will always be valid and {@link ValidatedVariable#validValue}
* will be equal to {@link Variable#value}.
*/
readonly validator: Validator<V, T> | null;
constructor(initialValue: V, validator?: Validator<V, T> | null);
get valid(): boolean;
get validValue(): T;
setValue(value: V, group?: unknown): boolean;
validate(value: V): ValidationResult<T>;
private validateAndSet;
}