Skip to content

Commit 96c6042

Browse files
author
Bero
committed
Replacing _.isArray with Array.isArray
1 parent 74b0106 commit 96c6042

7 files changed

+14
-14
lines changed

lib/links/lib/createSearchFilters.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ function getIdQueryFieldStorage(object, fieldStorage, isMany = false) {
3030
const [root, ...rest] = fieldStorage.split('.');
3131
if (rest.length === 0) {
3232
const ids = object[fieldStorage];
33-
return _.isArray(ids) ? {$in: ids} : ids;
33+
return Array.isArray(ids) ? {$in: ids} : ids;
3434
}
3535

3636
const nestedPath = rest.join('.');
3737
const rootValue = object[root];
38-
if (_.isArray(rootValue)) {
38+
if (Array.isArray(rootValue)) {
3939
return {$in: _.uniq(_.union(...rootValue.map(item => dot.pick(nestedPath, item))))};
4040
}
4141
else if (_.isObject(rootValue)) {

lib/query/hypernova/aggregateSearchFilters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function getIdsFromObject(object, field) {
88
}
99

1010
const rootValue = object[parts[0]];
11-
if (_.isArray(rootValue)) {
11+
if (Array.isArray(rootValue)) {
1212
return rootValue.map(item => dot.pick(parts.slice(1).join('.'), item));
1313
}
1414
else if (_.isObject(rootValue)) {

lib/query/hypernova/assembler.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ function getIdsForMany(parentResult, fieldStorage) {
5757

5858
// Option A.
5959
if (nested.length === 0) {
60-
return _.isArray(value) ? value : [value];
60+
return Array.isArray(value) ? value : [value];
6161
}
6262

6363
// Option C.
64-
if (_.isArray(value)) {
64+
if (Array.isArray(value)) {
6565
return _.flatten(value.map(v => getIdsFromObject(v, nested.join('.'))));
6666
}
6767

@@ -75,7 +75,7 @@ function getIdsForMany(parentResult, fieldStorage) {
7575

7676
function getIdsFromObject(object, path) {
7777
const pickedValue = dot.pick(path, object);
78-
return _.isArray(pickedValue) ? pickedValue : ((_.isUndefined(pickedValue) || _.isNull(pickedValue)) ? [] : [pickedValue]);
78+
return Array.isArray(pickedValue) ? pickedValue : ((_.isUndefined(pickedValue) || _.isNull(pickedValue)) ? [] : [pickedValue]);
7979
}
8080

8181
export function assembleMany(parentResult, {
@@ -94,7 +94,7 @@ export function assembleMany(parentResult, {
9494
}
9595

9696
const [, ...nestedLinkPath] = childCollectionNode.linkName.split('.');
97-
if (nestedLinkPath.length > 0 && _.isArray(rootValue)) {
97+
if (nestedLinkPath.length > 0 && Array.isArray(rootValue)) {
9898
rootValue.forEach(result => {
9999
const results = _.flatten(_.union(...getIdsForMany(result, rest.join('.')).map(id => resultsByKeyId[id])));
100100
const data = filterAssembledData(
@@ -173,7 +173,7 @@ export function assembleOne(parentResult, {
173173
// todo: using linker.linkName should be correct here since it should be the same as childCollectionNode.linkName
174174
const path = childCollectionNode.linkName.split('.');
175175

176-
if (_.isArray(rootValue)) {
176+
if (Array.isArray(rootValue)) {
177177
rootValue.forEach(result => {
178178
const value = dot.pick(rest.join('.'), result);
179179
const data = filterAssembledData(

lib/query/hypernova/buildVirtualNodeProps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function (childCollectionNode, filters, options, userId) {
2828
delete a[key];
2929
}
3030

31-
if (!_.isArray(value) && _.isObject(value) && !(value instanceof Date)) {
31+
if (!Array.isArray(value) && _.isObject(value) && !(value instanceof Date)) {
3232
a[key] = cleanUndefinedLeafs(value);
3333
}
3434
});

lib/query/hypernova/processVirtualNode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function(childCollectionNode, results, metaFilters, options = {})
6262
if (isMany) {
6363
comparator = (result, parent) => {
6464
const [root, ...nestedFields] = linkField.split('.');
65-
const rootValue = _.isArray(result[root]) ? result[root] : [result[root]];
65+
const rootValue = Array.isArray(result[root]) ? result[root] : [result[root]];
6666
if (nestedFields.length > 0) {
6767
return _.contains(rootValue.map(nestedObject => dot.pick(nestedFields.join('.'), nestedObject)), parent[linker.foreignIdentityField]);
6868
}

lib/query/lib/prepareForDelivery.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function removeLinkStorages(node, sameLevelResults) {
144144

145145
function removeArrayFromObject(result, linkName) {
146146
const linkData = dot.pick(linkName, result);
147-
if (linkData && _.isArray(linkData)) {
147+
if (linkData && Array.isArray(linkData)) {
148148
dot.remove(linkName, result);
149149
dot.str(linkName, _.first(linkData), result);
150150
}
@@ -154,7 +154,7 @@ function removeArrayForOneResult(result, linkName) {
154154
const [root, ...rest] = linkName.split('.');
155155

156156
const rootValue = result[root];
157-
if (rest.length > 0 && _.isArray(rootValue)) {
157+
if (rest.length > 0 && Array.isArray(rootValue)) {
158158
rootValue.forEach(value => {
159159
removeArrayFromObject(value, rest.join('.'));
160160
});
@@ -183,7 +183,7 @@ export function storeOneResults(node, sameLevelResults) {
183183
}
184184
else {
185185
const rootValue = result[root];
186-
if (_.isArray(rootValue)) {
186+
if (Array.isArray(rootValue)) {
187187
rootValue.forEach(value => {
188188
storeOneResults(collectionNode, dot.pick(rest.join('.'), value));
189189
});

lib/query/lib/recursiveFetch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function fetch(node, parentObject, fetchOptions = {}) {
5252
}
5353
else {
5454
const value = result[root];
55-
if (_.isArray(value)) {
55+
if (Array.isArray(value)) {
5656
const [, ...storageRest] = collectionNode.linker.linkStorageField.split('.');
5757
const nestedPath = storageRest.join('.');
5858
value.forEach(item => {

0 commit comments

Comments
 (0)