Skip to content
Permalink
Browse files

[enzyme] [patch] use `array.prototype.flat`

  • Loading branch information...
ljharb committed Jul 30, 2018
1 parent 35bffa6 commit e52a02ddac0fab0d1d93fd57d7f073f8bdc850bf
@@ -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';
@@ -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) {
@@ -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 {
@@ -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);
}
@@ -1,4 +1,4 @@
import flatten from 'lodash/flatten';
import flat from 'array.prototype.flat';
import compact from 'lodash/compact';
import cheerio from 'cheerio';

@@ -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);
}
@@ -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';
@@ -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.
You can’t perform that action at this time.