Skip to content

Commit 8d2ea70

Browse files
authored
Update service-module.getters.ts
- Apply destructuring directly on arguments - Only call select on "tempsById" if record is undefined and return record early otherwise - Convert ternary to "short-circuiting"
1 parent ec2ab69 commit 8d2ea70

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/service-module/service-module.getters.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ export default function makeServiceGetters() {
6969
data: values
7070
}
7171
},
72-
get: state => (id, params = {}) => {
73-
const { keyedById, tempsById, idField, tempIdField } = state
74-
const record = keyedById[id]
75-
? select(params, idField)(keyedById[id])
76-
: undefined
77-
const tempRecord = tempsById[id]
78-
? select(params, tempIdField)(tempsById[id])
79-
: undefined
80-
return record || tempRecord || null
72+
get: ({ keyedById, tempsById, idField, tempIdField }) =>
73+
(id, params = {}) => {
74+
const record = keyedById[id] && select(params, idField)(keyedById[id]);
75+
if (record) {
76+
return record;
77+
}
78+
const tempRecord =
79+
tempsById[id] && select(params, tempIdField)(tempsById[id]);
80+
81+
return tempRecord || null;
8182
},
8283
getCopyById: state => id => {
8384
const { servicePath, keepCopiesInStore, serverAlias } = state

0 commit comments

Comments
 (0)