UNPKG

@studiohyperdrive/ngx-utils

Version:

A series of abstracts, utils, pipes and services for Angular applications.

61 lines (60 loc) 2.58 kB
import { OnDestroy, OnInit } from '@angular/core'; import { AbstractControl } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { Observable, Subject } from 'rxjs'; import * as i0 from "@angular/core"; export type StringifiedQueryParamsType<QueryParamsType> = { [key in keyof QueryParamsType]: string; }; export declare abstract class NgxQueryParamFormSyncComponent<QueryParamsType, FormType extends AbstractControl> implements OnInit, OnDestroy { protected readonly route: ActivatedRoute; protected readonly router: Router; protected readonly destroyed$: Subject<void>; /** * The form in which we will save the queryParam data */ form: FormType; /** * The query params we wish to form */ protected queryParams$: Observable<StringifiedQueryParamsType<QueryParamsType>>; constructor(route: ActivatedRoute, router: Router); ngOnInit(): void; ngOnDestroy(): void; /** * Clears the data in the form */ clearData(): void; /** * Sets the provided data in the route, so the filtered view can be shared by url * * @param data - The provided data */ private setDataInRoute; /** * A method that that will provide a form that will be used to store the current data */ protected abstract initForm(): FormType; /** * An optional method that will handle what happens when the data have been updated. Do NOT subscribe to an Observable in this method. * * This method is useful in case you wish to save your currently selected data to a global state. * * @param data - The data provided by the form */ protected abstract handleDataChanges?(data: QueryParamsType): void; /** * An optional method to scramble the parameters if needed, so no data gets added into the route that shouldn't be shared * * @param params - The provided params we wish to set in the route */ protected scrambleParams?(params: QueryParamsType): QueryParamsType; /** * An optional method to unscramble the parameters if needed, so no data gets added into the route that shouldn't be shared * * @param params - The provided params we wish to patch in the form */ protected unscrambleParams?(params: QueryParamsType): QueryParamsType; static ɵfac: i0.ɵɵFactoryDeclaration<NgxQueryParamFormSyncComponent<any, any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<NgxQueryParamFormSyncComponent<any, any>, never, never, {}, {}, never, never, true, never>; }