1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 12:41:44 +02:00

update warning text to be more helpful

This commit is contained in:
Ian Storm Taylor
2016-11-18 12:07:54 -08:00
parent e189add154
commit 0f9cc69630
6 changed files with 18 additions and 12 deletions

View File

@@ -104,7 +104,7 @@ class Node extends React.Component {
if (!IS_DEV || !Immutable.is(nextProps.node, this.props.node)) { if (!IS_DEV || !Immutable.is(nextProps.node, this.props.node)) {
return true return true
} else { } else {
warn('Encountered different references for identical node values in "shouldComponentUpdate". Check that you are preserving references for the following node:\n', nextProps.node.toJS()) warn('A new immutable Node instance was encountered with an identical structure to the previous instance. This is usually a mistake and can impact performance. Make sure to preserve immutable references when nothing has changed. The node in question was:', nextProps.node)
} }
} }

View File

@@ -325,7 +325,7 @@ class Selection extends new Record(DEFAULTS) {
// If the anchor node isn't a text node, match it to one. // If the anchor node isn't a text node, match it to one.
if (anchorNode.kind != 'text') { if (anchorNode.kind != 'text') {
warn('Selection anchor is on a non text node, matching to leaf') warn('The selection anchor was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', anchorNode)
let anchorText = anchorNode.getTextAtOffset(anchorOffset) let anchorText = anchorNode.getTextAtOffset(anchorOffset)
let offset = anchorNode.getOffset(anchorText) let offset = anchorNode.getOffset(anchorText)
anchorOffset = anchorOffset - offset anchorOffset = anchorOffset - offset
@@ -334,7 +334,7 @@ class Selection extends new Record(DEFAULTS) {
// If the focus node isn't a text node, match it to one. // If the focus node isn't a text node, match it to one.
if (focusNode.kind != 'text') { if (focusNode.kind != 'text') {
warn('Selection focus is on a non text node, matching to leaf') warn('The selection focus was set to a Node that is not a Text node. This should not happen and can degrade performance. The node in question was:', focusNode)
let focusText = focusNode.getTextAtOffset(focusOffset) let focusText = focusNode.getTextAtOffset(focusOffset)
let offset = focusNode.getOffset(focusText) let offset = focusNode.getOffset(focusText)
focusOffset = focusOffset - offset focusOffset = focusOffset - offset

View File

@@ -350,12 +350,15 @@ function setNode(state, operation) {
let { document } = state let { document } = state
let node = document.assertPath(path) let node = document.assertPath(path)
// Deprecate using setNode for updating children, or keys // Deprecate the ability to overwite a node's children.
if (properties.nodes && properties.nodes != node.nodes) { if (properties.nodes && properties.nodes != node.nodes) {
warn('Updating Node.nodes through setNode is not allowed. Use appropriate insertion and removal functions.') warn('Updating a Node\'s `nodes` property via `setNode()` is not allowed. Use the appropriate insertion and removal operations instead. The opeartion in question was:', operation)
delete properties.nodes delete properties.nodes
} else if (properties.key && properties.key != node.key) { }
warn('Updating Node.key through setNode is not allowed. You should not have to update keys yourself.')
// Deprecate the ability to change a node's key.
if (properties.key && properties.key != node.key) {
warn('Updating a Node\'s `key` property via `setNode()` is not allowed. There should be no reason to do this. The opeartion in question was:', operation)
delete properties.key delete properties.key
} }

View File

@@ -102,7 +102,7 @@ export function normalizeSelection(transform) {
!document.hasDescendant(selection.anchorKey) || !document.hasDescendant(selection.anchorKey) ||
!document.hasDescendant(selection.focusKey) !document.hasDescendant(selection.focusKey)
) { ) {
warn('The selection was invalid and reset to start of the document.') warn('The selection was invalid and was reset to start of the document. The selection in question was:', selection)
const firstText = document.getFirstText() const firstText = document.getFirstText()
selection = selection.merge({ selection = selection.merge({

View File

@@ -59,7 +59,7 @@ function inline(value) {
function key(value) { function key(value) {
if (typeOf(value) == 'string') return value if (typeOf(value) == 'string') return value
warn('Deprecation: Passing a node instead of a key to a method accepting a key can reduce performances') warn('An object was passed to a Node method instead of a `key` string. This was previously supported, but is being deprecated because it can have a negative impact on performance. The object in question was:', value)
if (value instanceof Block) return value.key if (value instanceof Block) return value.key
if (value instanceof Document) return value.key if (value instanceof Document) return value.key
if (value instanceof Inline) return value.key if (value instanceof Inline) return value.key

View File

@@ -5,15 +5,16 @@ import IS_DEV from '../constants/is-dev'
* Log a development warning. * Log a development warning.
* *
* @param {String} message * @param {String} message
* @param {Any} ...args
*/ */
function warning(message, ...more) { function warn(message, ...args) {
if (!IS_DEV) { if (!IS_DEV) {
return return
} }
if (typeof console !== 'undefined') { if (typeof console !== 'undefined') {
console.error(`Warning: ${message}`, ...more) // eslint-disable-line no-console console.warn(`Warning: ${message}`, ...args) // eslint-disable-line no-console
} }
try { try {
@@ -28,6 +29,8 @@ function warning(message, ...more) {
/** /**
* Export. * Export.
*
* @type {Function}
*/ */
export default warning export default warn