From 843485089006ed38109ae19d4a05bd91b27c1ed5 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 17 Aug 2016 12:56:50 -0700 Subject: [PATCH] cleanup --- lib/models/node.js | 1 - lib/models/transform.js | 14 +++++++++++ lib/transforms/by-key.js | 52 +++++++++------------------------------- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/lib/models/node.js b/lib/models/node.js index 47d2ceff6..0ad8e8836 100644 --- a/lib/models/node.js +++ b/lib/models/node.js @@ -765,7 +765,6 @@ const Node = { */ getPath(key) { - debugger key = Normalize.key(key) if (key == this.key) return [] diff --git a/lib/models/transform.js b/lib/models/transform.js index 6a4437974..f63000d39 100644 --- a/lib/models/transform.js +++ b/lib/models/transform.js @@ -76,6 +76,20 @@ class Transform { return 'transform' } + /** + * Add an `operation` to the transform that resulted in `state`. + * + * @param {State} state + * @param {Object} operation + * @return {Transform} + */ + + add(state, operation) { + this.state = state + this.operations.push(operation) + return this + } + /** * Apply the transform and return the new state. * diff --git a/lib/transforms/by-key.js b/lib/transforms/by-key.js index 1c370e7ae..c3d1d0102 100644 --- a/lib/transforms/by-key.js +++ b/lib/transforms/by-key.js @@ -25,16 +25,13 @@ export function addMarkByKey(transform, key, offset, length, mark) { document = document.updateDescendant(node) state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'add-mark', - offset, length, mark, + offset, path, }) - - return transform } /** @@ -60,15 +57,12 @@ export function insertNodeByKey(transform, key, index, node) { document = document.normalize() state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'insert-node', index, node, path, }) - - return transform } /** @@ -92,16 +86,13 @@ export function insertTextByKey(transform, key, offset, text, marks) { document = document.updateDescendant(node) state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'insert-text', offset, marks, path, text, }) - - return transform } /** @@ -135,15 +126,12 @@ export function moveNodeByKey(transform, key, newKey, newIndex) { document = document.normalize() state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'move-node', path, newPath, newIndex, }) - - return transform } /** @@ -169,16 +157,13 @@ export function removeMarkByKey(transform, key, offset, length, mark) { document = document.updateDescendant(node) state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'remove-mark', offset, length, mark, path, }) - - return transform } /** @@ -203,13 +188,10 @@ export function removeNodeByKey(transform, key) { document = document.normalize() state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'remove-node', path, }) - - return transform } /** @@ -233,15 +215,12 @@ export function removeTextByKey(transform, key, offset, length) { document = document.normalize() state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'remove-text', offset, length, path, }) - - return transform } /** @@ -268,8 +247,7 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) { document = document.updateDescendant(node) state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'set-mark', offset, length, @@ -277,8 +255,6 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) { path, properties, }) - - return transform } /** @@ -303,14 +279,11 @@ export function setNodeByKey(transform, key, properties) { document = document.normalize() state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'set-node', path, properties, }) - - return transform } /** @@ -366,13 +339,10 @@ export function splitNodeByKey(transform, key, offset) { document = isParent ? parent : document.updateDescendant(parent) state = state.merge({ document }) - transform.state = state - transform.operations.push({ + return transform.add(state, { type: 'split-node', offset, path, }) - - return transform }