From 97aa3ecd93e859b937043cd0af228690b255d3b4 Mon Sep 17 00:00:00 2001 From: Soreine Date: Wed, 26 Oct 2016 15:59:06 +0200 Subject: [PATCH 1/2] Deprecating using setNode to update `nodes` --- src/transforms/apply-operation.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/transforms/apply-operation.js b/src/transforms/apply-operation.js index 32720c0c4..2b77259da 100644 --- a/src/transforms/apply-operation.js +++ b/src/transforms/apply-operation.js @@ -1,5 +1,6 @@ import Debug from 'debug' +import warning from '../utils/warning' /** * Debug. @@ -294,6 +295,12 @@ function setNode(state, operation) { const { path, properties } = operation let { document } = state let node = document.assertPath(path) + + // Deprecate using setNode for updating children + if (properties.nodes && properties.nodes != node.nodes) { + warning('Updating Node.nodes through setNode is deprecated. Use the appropriate insertion and removal functions, rather than, for example, setNodeByKey.') + } + node = node.merge(properties) document = document.updateDescendant(node) state = state.merge({ document }) From 62b8ed205edacb2bb99ad9b50cd1196abd18449b Mon Sep 17 00:00:00 2001 From: Soreine Date: Wed, 26 Oct 2016 16:17:05 +0200 Subject: [PATCH 2/2] setNode cannot be used to update key and nodes --- src/transforms/apply-operation.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/transforms/apply-operation.js b/src/transforms/apply-operation.js index 2b77259da..3a6bf4f27 100644 --- a/src/transforms/apply-operation.js +++ b/src/transforms/apply-operation.js @@ -296,9 +296,13 @@ function setNode(state, operation) { let { document } = state let node = document.assertPath(path) - // Deprecate using setNode for updating children + // Deprecate using setNode for updating children, or keys if (properties.nodes && properties.nodes != node.nodes) { - warning('Updating Node.nodes through setNode is deprecated. Use the appropriate insertion and removal functions, rather than, for example, setNodeByKey.') + warning('Updating Node.nodes through setNode is not allowed. Use appropriate insertion and removal functions.') + delete properties.nodes + } else if (properties.key && properties.key != node.key) { + warning('Updating Node.key through setNode is not allowed. You should not have to update keys yourself.') + delete properties.key } node = node.merge(properties)