Skip to content

Commit

Permalink
pouchdb-utils/flatten: replace with Array.flat() built-in (#8929)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Apr 23, 2024
1 parent e5731fa commit 2e48ed7
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 18 deletions.
5 changes: 2 additions & 3 deletions packages/node_modules/pouchdb-abstract-mapreduce/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
flatten,
guardedConsole,
nextTick,
isRemote
Expand Down Expand Up @@ -486,7 +485,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
return Promise.all(docIds.map(function (docId) {
return getDocsToPersist(docId, view, docIdsToChangesAndEmits);
})).then(function (listOfDocsToPersist) {
var docsToPersist = flatten(listOfDocsToPersist);
var docsToPersist = listOfDocsToPersist.flat();
lastSeqDoc.seq = seq;
docsToPersist.push(lastSeqDoc);
// write all docs in a single operation, update the seq once
Expand Down Expand Up @@ -853,7 +852,7 @@ function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
return fetchFromView(viewOpts);
});
const result = await Promise.all(fetchPromises);
const flattenedResult = flatten(result);
const flattenedResult = result.flat();
return onMapResultsReady(flattenedResult);
} else { // normal query, no 'keys'
const viewOpts = {
Expand Down
3 changes: 1 addition & 2 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
clone,
parseUri,
bulkGetShim,
flatten,
nextTick
} from 'pouchdb-utils';

Expand Down Expand Up @@ -377,7 +376,7 @@ function HttpPouch(opts, callback) {
// err is impossible because shim returns a list of errs in that case
results[batchNum] = res.results;
if (++numDone === numBatches) {
callback(null, {results: flatten(results)});
callback(null, {results: results.flat()});
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/node_modules/pouchdb-replication/src/getDocs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clone, flatten, isRemote } from 'pouchdb-utils';
import { clone, isRemote } from 'pouchdb-utils';

function fileHasChanged(localDoc, remoteDoc, filename) {
return !localDoc._attachments ||
Expand Down Expand Up @@ -112,7 +112,7 @@ function getDocs(src, target, diffs, state) {
}))

.then(function (results) {
resultDocs = resultDocs.concat(flatten(results).filter(Boolean));
resultDocs = resultDocs.concat(results.flat().filter(Boolean));
});
});
}
Expand Down
9 changes: 0 additions & 9 deletions packages/node_modules/pouchdb-utils/src/flatten.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/node_modules/pouchdb-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import guardedConsole from './guardedConsole';
import defaultBackOff from './defaultBackOff';
import explainError from './explainError';
import filterChange from './filterChange';
import flatten from './flatten';
import functionName from './functionName';
import hasLocalStorage from './env/hasLocalStorage';
import invalidIdError from './invalidIdError';
Expand All @@ -35,7 +34,6 @@ export {
defaultBackOff,
explainError,
filterChange,
flatten,
functionName,
guardedConsole,
hasLocalStorage,
Expand Down

0 comments on commit 2e48ed7

Please sign in to comment.