UNPKG

@ngneat/reactive-forms

Version:

(Angular Reactive) Forms with Benefits

34 lines (33 loc) 1.65 kB
import { AbstractControl, UntypedFormArray } from "@angular/forms"; import { Observable } from "rxjs"; export interface PersistOptions<T> { debounceTime?: number; manager?: PersistManager<T>; arrControlFactory?: ControlFactoryMap<T>; persistDisabledControls?: boolean; } export declare function persistControl<T>(control: AbstractControl, key: string, { debounceTime, manager, arrControlFactory, persistDisabledControls }: PersistOptions<T>): Observable<unknown>; export declare function restoreControl<T>(control: AbstractControl, key: string, manager: PersistManager<T>, arrControlFactory: ControlFactoryMap<T> | undefined): Observable<T>; export declare function clearFormArray(control: UntypedFormArray): void; export declare function wrapIntoObservable<T>(value: T | Promise<T> | Observable<T>): Observable<T>; export declare type ArrayKeys<T> = { [K in keyof T]: T[K] extends any[] ? K : never; }[keyof T]; export declare type ControlFactory<T> = (value: T) => AbstractControl; export declare type ControlFactoryMap<T> = { [K in ArrayKeys<T>]?: ControlFactory<ArrayType<T[K]>>; }; declare type ArrayType<T> = T extends Array<infer R> ? R : any; export interface PersistManager<T> { setValue(key: string, data: T): T | Promise<T> | Observable<T>; getValue(key: string): T | Promise<T> | Observable<T>; } export declare class LocalStorageManager<T> implements PersistManager<T> { setValue(key: string, data: T): T; getValue(key: string): T; } export declare class SessionStorageManager<T> implements PersistManager<T> { setValue(key: string, data: T): T; getValue(key: string): T; } export {};