1- import { isOptionalFunction , wrapTryCatch } from './util' ;
1+ import { Comparator , isOptionalFunction , wrapTryCatch } from './util' ;
2+ import { createEmptyOnDeserializer , createEmptyOnSerializer } from './serializers' ;
23
34/** TODO Documentation */
45export type ParamSerializer < T > = ( model : T | null ) => string | null ;
@@ -10,10 +11,18 @@ export type ParamDeserializer<T> = (value: string | null) => T | null;
1011 * TODO Documentation
1112 */
1213export interface QueryParamControlOpts < T > {
14+ /** TODO Documentation */
1315 name : string ;
16+ /** TODO Documentation */
1417 serialize : ParamSerializer < T > ;
18+ /** TODO Documentation */
1519 deserialize : ParamDeserializer < T > ;
20+ /** TODO Documentation */
21+ compareWith : Comparator < T > ;
22+ /** TODO Documentation */
1623 debounceTime ?: number | null ;
24+ /** TODO Documentation */
25+ emptyOn ?: T | null ;
1726}
1827
1928/**
@@ -35,23 +44,26 @@ export class QueryParamGroup {
3544 */
3645export class QueryParamControl < T > {
3746
38- /** TODO Documentation */
39- public name : string | null = null ;
47+ /** TODO Documentation See QueryParamControlOpts */
48+ public name : string | null ;
4049
41- /** TODO Documentation */
50+ /** TODO Documentation See QueryParamControlOpts */
4251 public serialize : ParamSerializer < T > ;
4352
44- /** TODO Documentation */
53+ /** TODO Documentation See QueryParamControlOpts */
4554 public deserialize : ParamDeserializer < T > ;
4655
47- /** TODO Documentation */
48- public debounceTime : number | null = null ;
56+ /** TODO Documentation See QueryParamControlOpts */
57+ public compareWith : Comparator < T > ;
58+
59+ /** TODO Documentation See QueryParamControlOpts */
60+ public debounceTime : number | null ;
4961
5062 /** TODO Documentation */
5163 public value : T = null ;
5264
5365 constructor ( opts : QueryParamControlOpts < T > ) {
54- const { name, serialize, deserialize, debounceTime } = opts ;
66+ const { name, serialize, deserialize, debounceTime, emptyOn , compareWith } = opts ;
5567
5668 if ( ! isOptionalFunction ( serialize ) ) {
5769 throw new Error ( `serialize must be a function, but received ${ serialize } ` ) ;
@@ -61,9 +73,20 @@ export class QueryParamControl<T> {
6173 throw new Error ( `deserialize must be a function, but received ${ deserialize } ` ) ;
6274 }
6375
76+ if ( ! isOptionalFunction ( compareWith ) ) {
77+ throw new Error ( `compareWith must be a function, but received ${ compareWith } ` ) ;
78+ }
79+
6480 this . name = name ;
65- this . serialize = wrapTryCatch ( serialize , `Error while serializing value for ${ name || 'control' } ` ) ;
66- this . deserialize = wrapTryCatch ( deserialize , `Error while deserializing value for ${ name || 'control' } ` ) ;
81+ this . serialize = wrapTryCatch (
82+ createEmptyOnSerializer ( serialize , emptyOn , compareWith ) ,
83+ `Error while serializing value for ${ name || 'control' } `
84+ ) ;
85+ this . deserialize = wrapTryCatch (
86+ createEmptyOnDeserializer ( deserialize , emptyOn ) ,
87+ `Error while deserializing value for ${ name || 'control' } `
88+ ) ;
89+ this . compareWith = compareWith ;
6790 this . debounceTime = debounceTime ;
6891 }
6992
0 commit comments