Skip to content

Commit

Permalink
fix(core): Changing switch to a map (#7236)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmquach committed Jul 17, 2019
1 parent d3249c9 commit 73d4f4c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions app/scripts/modules/core/src/filterModel/FilterModelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,18 @@ export class FilterModelService {

// Maps router param values to sortFilter values, applying known default values if the parameter is missing
public static mapRouterParamsToSortFilter(filterModel: IFilterModel, params: any) {
const getValueIfNill = (filterType: string) => {
switch (filterType) {
case 'trueKeyObject':
return {};
case 'string':
return '';
case 'boolean':
return false;
case 'inverse-boolean':
return true;
}
return undefined;
const filterTypeDefaults: { [key: string]: any } = {
trueKeyObject: {},
string: '',
boolean: false,
'inverse-boolean': true,
};

const iFilterConfigs = filterModel.config;

return iFilterConfigs.reduce(
(acc, filter) => {
const valueIfNil = getValueIfNill(filter.type);
const valueIfNil = filterTypeDefaults[filter.type];
const rawValue = params[filter.param];
const paramValue = isNil(rawValue) ? valueIfNil : rawValue;
// Clone deep so angularjs mutations happen on a different object reference
Expand Down

0 comments on commit 73d4f4c

Please sign in to comment.