Skip to content

Commit

Permalink
[enzyme] [patch] use array.prototype.flat
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 30, 2018
1 parent 35bffa6 commit e52a02d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/enzyme/src/RSTTraversal.js
@@ -1,4 +1,4 @@
import flatten from 'lodash/flatten';
import flat from 'array.prototype.flat';
import entries from 'object.entries';
import isSubset from 'is-subset';
import functionName from 'function.prototype.name';
Expand All @@ -9,7 +9,7 @@ export function propsOfNode(node) {

export function childrenOfNode(node) {
if (!node) return [];
return Array.isArray(node.rendered) ? flatten(node.rendered, true) : [node.rendered];
return Array.isArray(node.rendered) ? flat(node.rendered, 1) : [node.rendered];
}

export function hasClassName(node, className) {
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/ReactWrapper.js
@@ -1,5 +1,5 @@
import cheerio from 'cheerio';
import flatten from 'lodash/flatten';
import flat from 'array.prototype.flat';
import compact from 'lodash/compact';

import {
Expand Down Expand Up @@ -905,7 +905,7 @@ class ReactWrapper {
*/
flatMap(fn) {
const nodes = this.getNodesInternal().map((n, i) => fn.call(this, this.wrap(n), i));
const flattened = flatten(nodes, true);
const flattened = flat(nodes, 1);
const compacted = compact(flattened);
return this.wrap(compacted);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/ShallowWrapper.js
@@ -1,4 +1,4 @@
import flatten from 'lodash/flatten';
import flat from 'array.prototype.flat';
import compact from 'lodash/compact';
import cheerio from 'cheerio';

Expand Down Expand Up @@ -1099,7 +1099,7 @@ class ShallowWrapper {
*/
flatMap(fn) {
const nodes = this.getNodesInternal().map((n, i) => fn.call(this, this.wrap(n), i));
const flattened = flatten(nodes, true);
const flattened = flat(nodes, 1);
const compacted = compact(flattened);
return this.wrap(compacted);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/selectors.js
@@ -1,7 +1,7 @@
import { createParser } from 'rst-selector-parser';
import values from 'object.values';
import isEmpty from 'lodash/isEmpty';
import flatten from 'lodash/flatten';
import flat from 'array.prototype.flat';
import unique from 'lodash/uniq';
import is from 'object-is';
import has from 'has';
Expand Down Expand Up @@ -422,5 +422,5 @@ export function reduceTreeBySelector(selector, root) {

export function reduceTreesBySelector(selector, roots) {
const results = roots.map(n => reduceTreeBySelector(selector, n));
return unique(flatten(results));
return unique(flat(results, 1));
}

0 comments on commit e52a02d

Please sign in to comment.