From 6672f553e92eb53fca9e65df39bb242a30da026b Mon Sep 17 00:00:00 2001 From: Brendan Date: Mon, 19 Aug 2019 11:19:24 -0500 Subject: [PATCH] Mutate newDirtyPaths instead of creating a new array every iteration (#2559) * Mutate newDirtyPaths instead of creating a new array every iteration * Switch to map + Array.prototype.concat.apply to improve readability * Update editor.js --- packages/slate/src/controllers/editor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 9ad88d624..5ef061a56 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -100,14 +100,14 @@ class Editor { // Get the paths of the affected nodes, and mark them as dirty. const newDirtyPaths = getDirtyPaths(operation) - const dirty = this.tmp.dirty.reduce((memo, path) => { + + const dirty = this.tmp.dirty.map(path => { path = PathUtils.create(path) const transformed = PathUtils.transform(path, operation) - memo = memo.concat(transformed.toArray()) - return memo - }, newDirtyPaths) + return transformed.toArray() + }) - this.tmp.dirty = dirty + this.tmp.dirty = Array.prototype.concat.apply(newDirtyPaths, dirty) // If we're not already, queue the flushing process on the next tick. if (!this.tmp.flushing) {