Skip to content

Commit

Permalink
refactor logic for filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohenho committed Mar 11, 2022
1 parent 35d24a1 commit ce4fe88
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,24 +369,18 @@ function opts (pragma) {
};
let props = opt[key];
// If the filter options for an event exist, the props are returned as an array instead of an object.
if (Array.isArray(props)) {
let lambdaKeys = props;
lambdaKeys.forEach(eventName => {
lambda.events[eventName] = [];
obj.lambdas.push(lambda);
});
} else {
let lambdaKeys = Object.keys(props);
lambdaKeys.forEach(eventName => {
let hasFilters = Array.isArray(props);
let lambdaKeys = hasFilters ? props : Object.keys(props);
lambdaKeys.forEach(eventName => {
lambda.events[eventName] = [];
if (!hasFilters) {
let filterPairs = props[eventName];
lambda.events[eventName] = [];
for (let i = 0; i < filterPairs.length - 1; i++) {
if (i % 2 === 1) continue;
lambda.events[eventName].push([ filterPairs[i], filterPairs[i + 1] ]);
lambda.events[eventName].push([filterPairs[i], filterPairs[i + 1]]);
}
});
obj.lambdas.push(lambda);
}
}
});
obj.lambdas.push(lambda);
} else {
obj[key] = opt[key];
Expand Down

0 comments on commit ce4fe88

Please sign in to comment.