UNPKG

@roqueform/reset-plugin

Version:
43 lines (42 loc) 1.6 kB
import { Field, PluginInjector, PluginOf, Subscriber, Unsubscribe, ValueOf } from 'roqueform'; /** * The plugin added to fields by the {@link resetPlugin}. */ export interface ResetPlugin { /** * `true` if the field value is different from its initial value. */ readonly isDirty: boolean; /** * Sets the initial value of the field and notifies ancestors and descendants. * * @param value The initial value to set. */ setInitialValue(value: ValueOf<this>): void; /** * Reverts the field to its initial value. */ reset(): void; /** * Returns all fields that have {@link roqueform!BareField.value a value} that is different from * {@link roqueform!BareField.initialValue an initial value}. * * @see {@link isDirty} */ getDirtyFields(): Field<any, PluginOf<this>>[]; /** * Subscribes to changes of {@link roqueform!BareField.initialValue the initial value}. * * @param eventType The type of the event. * @param subscriber The subscriber that would be triggered. * @returns The callback to unsubscribe the subscriber. */ on(eventType: 'change:initialValue', subscriber: Subscriber<any, PluginOf<this>>): Unsubscribe; } /** * Enhances fields with methods that manage the initial value. * * @param equalityChecker The callback that compares initial value and the current value of the field. By default, the * deep comparison is used. */ export declare function resetPlugin(equalityChecker?: (initialValue: any, value: any) => boolean): PluginInjector<ResetPlugin>;