Skip to content

Commit 3158e70

Browse files
committed
feat: inline loops
1 parent deaef0a commit 3158e70

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88
},
99
"plugins": [
10+
"macros",
1011
"@babel/transform-flow-strip-types"
1112
],
1213
"presets": [

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
},
2121
"bin": "./dist/bin/index.js",
2222
"dependencies": {
23+
"babel-plugin-macros": "^2.6.1",
2324
"es6-error": "^4.1.1",
25+
"inline-loops.macro": "^1.0.3",
2426
"lodash": "^4.17.11",
2527
"pluralize": "^8.0.0",
2628
"roarr": "^2.13.2",

src/routines/getByIds.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
import {
77
camelCase
88
} from 'lodash';
9+
import {
10+
filter,
11+
find
12+
} from 'inline-loops.macro';
913
import Logger from '../Logger';
1014
import {
1115
NotFoundError
@@ -44,15 +48,15 @@ export default async (
4448

4549
if (resultIsArray) {
4650
for (const id of ids) {
47-
const result = rows.filter((row) => {
51+
const result = filter(rows, (row) => {
4852
return row[targetPropertyName] === id;
4953
});
5054

5155
results.push(result);
5256
}
5357
} else {
5458
for (const id of ids) {
55-
let result = rows.find((row) => {
59+
let result = find(rows, (row) => {
5660
return row[targetPropertyName] === id;
5761
});
5862

src/routines/getByIdsUsingJoiningTable.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import {
44
sql
55
} from 'slonik';
6+
import {
7+
filter
8+
} from 'inline-loops.macro';
69
import type {
710
DatabaseConnectionType
811
} from '../types';
@@ -32,7 +35,7 @@ export default async (
3235
const results = [];
3336

3437
for (const id of ids) {
35-
const result = rows.filter((row) => {
38+
const result = filter(rows, (row) => {
3639
return row.POSTLOADER_LOOKUP_KEY === id;
3740
});
3841

0 commit comments

Comments
 (0)