Skip to content

Commit 718c789

Browse files
committed
fix(core): Assert that emptyOn isn't used in multi-mode.
1 parent 9c8722a commit 718c789

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

projects/ngqp/core/src/lib/model.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface QueryParamControlOpts<T> {
3232
multi?: boolean;
3333
/** TODO Documentation */
3434
debounceTime?: number | null;
35-
/** TODO Documentation */
35+
/** TODO Documentation (+ not supported in multi-mode) */
3636
emptyOn?: T | null;
3737
}
3838

@@ -156,7 +156,8 @@ export class QueryParamControl<T> {
156156
private changeFunctions: OnChangeFunction<T>[] = [];
157157

158158
constructor(opts: QueryParamControlOpts<T>) {
159-
const { name, serialize, deserialize, debounceTime, emptyOn, compareWith, multi } = opts;
159+
const { name, serialize, deserialize, debounceTime, emptyOn, compareWith } = opts;
160+
const multi = opts.multi === true;
160161

161162
if (isMissing(name)) {
162163
throw new Error(`Please provide a name for each query parameter control.`);
@@ -174,6 +175,10 @@ export class QueryParamControl<T> {
174175
throw new Error(`compareWith must be a function, but received ${compareWith}`);
175176
}
176177

178+
if (multi && !isMissing(emptyOn)) {
179+
throw new Error(`emptyOn is only supported for single-value parameters, but ${name} is a multi-value parameter.`);
180+
}
181+
177182
this.name = name;
178183
this.serialize = wrapTryCatch(
179184
createEmptyOnSerializer(serialize, emptyOn, compareWith),
@@ -184,7 +189,7 @@ export class QueryParamControl<T> {
184189
`Error while deserializing value for ${name}`
185190
);
186191
this.compareWith = compareWith;
187-
this.multi = multi === true;
192+
this.multi = multi;
188193
this.debounceTime = debounceTime;
189194
}
190195

0 commit comments

Comments
 (0)