Skip to content

Commit

Permalink
feat: inline loops
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 14, 2019
1 parent deaef0a commit 3158e70
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
},
"plugins": [
"macros",
"@babel/transform-flow-strip-types"
],
"presets": [
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
},
"bin": "./dist/bin/index.js",
"dependencies": {
"babel-plugin-macros": "^2.6.1",
"es6-error": "^4.1.1",
"inline-loops.macro": "^1.0.3",
"lodash": "^4.17.11",
"pluralize": "^8.0.0",
"roarr": "^2.13.2",
Expand Down
8 changes: 6 additions & 2 deletions src/routines/getByIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
import {
camelCase
} from 'lodash';
import {
filter,
find
} from 'inline-loops.macro';
import Logger from '../Logger';
import {
NotFoundError
Expand Down Expand Up @@ -44,15 +48,15 @@ export default async (

if (resultIsArray) {
for (const id of ids) {
const result = rows.filter((row) => {
const result = filter(rows, (row) => {
return row[targetPropertyName] === id;
});

results.push(result);
}
} else {
for (const id of ids) {
let result = rows.find((row) => {
let result = find(rows, (row) => {
return row[targetPropertyName] === id;
});

Expand Down
5 changes: 4 additions & 1 deletion src/routines/getByIdsUsingJoiningTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import {
sql
} from 'slonik';
import {
filter
} from 'inline-loops.macro';
import type {
DatabaseConnectionType
} from '../types';
Expand Down Expand Up @@ -32,7 +35,7 @@ export default async (
const results = [];

for (const id of ids) {
const result = rows.filter((row) => {
const result = filter(rows, (row) => {
return row.POSTLOADER_LOOKUP_KEY === id;
});

Expand Down

0 comments on commit 3158e70

Please sign in to comment.