From 4dcbe1918a30c25624ed813c9e8ff3667b5a5794 Mon Sep 17 00:00:00 2001
From: Ian Storm Taylor <ian@ianstormtaylor.com>
Date: Wed, 22 Aug 2018 15:41:04 -0700
Subject: [PATCH] add deprecations

---
 packages/slate/src/changes/with-schema.js |  4 ++--
 packages/slate/src/interfaces/node.js     | 15 ++++++++++---
 packages/slate/src/models/text.js         | 27 +++++++++++++++++++----
 3 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/packages/slate/src/changes/with-schema.js b/packages/slate/src/changes/with-schema.js
index 6b93c97a9..51ab684b3 100644
--- a/packages/slate/src/changes/with-schema.js
+++ b/packages/slate/src/changes/with-schema.js
@@ -124,7 +124,7 @@ function normalizeNodeAndChildren(change, node, schema) {
     return
   }
 
-  let child = node.getFirstInvalidDescendant(schema)
+  let child = node.getFirstInvalidNode(schema)
   let path = change.value.document.getPath(node.key)
 
   while (node && child) {
@@ -136,7 +136,7 @@ function normalizeNodeAndChildren(change, node, schema) {
       child = null
     } else {
       path = change.value.document.refindPath(path, node.key)
-      child = node.getFirstInvalidDescendant(schema)
+      child = node.getFirstInvalidNode(schema)
     }
   }
 
diff --git a/packages/slate/src/interfaces/node.js b/packages/slate/src/interfaces/node.js
index e0e56cef6..d0f1abb91 100644
--- a/packages/slate/src/interfaces/node.js
+++ b/packages/slate/src/interfaces/node.js
@@ -501,17 +501,26 @@ class NodeInterface {
    * @return {Node|Text|Null}
    */
 
-  getFirstInvalidDescendant(schema) {
+  getFirstInvalidNode(schema) {
     let result = null
 
     this.nodes.find(n => {
-      result = n.validate(schema) ? n : n.getFirstInvalidDescendant(schema)
+      result = n.validate(schema) ? n : n.getFirstInvalidNode(schema)
       return result
     })
 
     return result
   }
 
+  getFirstInvalidDescendant(schema) {
+    logger.deprecate(
+      '0.39.0',
+      'The `Node.getFirstInvalidDescendant` method is deprecated, please use `Node.getFirstInvalidNode` instead.'
+    )
+
+    return this.getFirstInvalidNode(schema)
+  }
+
   /**
    * Get the first child text node.
    *
@@ -2164,7 +2173,7 @@ memoize(NodeInterface.prototype, [
   'getBlocksAtRangeAsArray',
   'getBlocksByTypeAsArray',
   'getDecorations',
-  'getFirstInvalidDescendant',
+  'getFirstInvalidNode',
   'getFirstText',
   'getFragmentAtRange',
   'getInlinesAsArray',
diff --git a/packages/slate/src/models/text.js b/packages/slate/src/models/text.js
index 5401b6163..30b4d6267 100644
--- a/packages/slate/src/models/text.js
+++ b/packages/slate/src/models/text.js
@@ -166,6 +166,7 @@ class Text extends Record(DEFAULTS) {
    */
 
   get isEmpty() {
+    logger.deprecate('0.39.0', 'The `Text.isEmpty` property is deprecated.')
     return this.text == ''
   }
 
@@ -176,7 +177,7 @@ class Text extends Record(DEFAULTS) {
    */
 
   get text() {
-    return this.getString()
+    return this.getText()
   }
 
   /**
@@ -185,10 +186,19 @@ class Text extends Record(DEFAULTS) {
    * @returns {String}
    */
 
-  getString() {
+  getText() {
     return this.leaves.reduce((string, leaf) => string + leaf.text, '')
   }
 
+  getString() {
+    logger.deprecate(
+      '0.39.0',
+      'The `Text.getString` property is deprecated, please use `Text.getText` instead.'
+    )
+
+    return this.getText()
+  }
+
   /**
    * Find the 'first' leaf at offset; By 'first' the alorighthm prefers `endOffset === offset` than `startOffset === offset`
    * Corner Cases:
@@ -739,10 +749,19 @@ class Text extends Record(DEFAULTS) {
    * @returns {Text|Null}
    */
 
-  getFirstInvalidDescendant(schema) {
+  getFirstInvalidNode(schema) {
     return this.validate(schema) ? this : null
   }
 
+  getFirstInvalidDescendant(schema) {
+    logger.deprecate(
+      '0.39.0',
+      'The `Node.getFirstInvalidDescendant` method is deprecated, please use `Node.getFirstInvalidNode` instead.'
+    )
+
+    return this.getFirstInvalidNode(schema)
+  }
+
   /**
    * Set leaves with normalized `leaves`
    *
@@ -783,7 +802,7 @@ memoize(Text.prototype, [
   'getMarksAsArray',
   'normalize',
   'validate',
-  'getString',
+  'getText',
   'getKeysToPathsTable',
 ])