Skip to content

Commit

Permalink
Deduplicate dirty paths for normalization. (ianstormtaylor#2916)
Browse files Browse the repository at this point in the history
* Deduplicate dirty paths for normalization.

* Update editor.js
  • Loading branch information
themithy authored and ianstormtaylor committed Aug 19, 2019
1 parent 8ab49c0 commit ff831eb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/slate/src/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,20 @@ class Editor {
return transformed.toArray()
})

this.tmp.dirty = Array.prototype.concat.apply(newDirtyPaths, dirty)
const pathIndex = {}
const dirtyPaths = Array.prototype.concat.apply(newDirtyPaths, dirty)
this.tmp.dirty = []

// PERF: De-dupe the paths so we don't do extra normalization.
dirtyPaths.forEach(dirtyPath => {
const key = dirtyPath.join(',')

if (!pathIndex[key]) {
this.tmp.dirty.push(dirtyPath)
}

pathIndex[key] = true
})

// If we're not already, queue the flushing process on the next tick.
if (!this.tmp.flushing) {
Expand Down

0 comments on commit ff831eb

Please sign in to comment.