mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 15:02:51 +02:00
fix editor resolution, remove constructor
This commit is contained in:
@@ -70,23 +70,25 @@ class Editor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Initial state.
|
||||||
*
|
*
|
||||||
* @param {Object} props
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constructor(props) {
|
state = {}
|
||||||
super(props)
|
|
||||||
this.resolvePlugins = memoizeOne(this.resolvePlugins)
|
|
||||||
this.state = {}
|
|
||||||
|
|
||||||
this.tmp = {
|
/**
|
||||||
|
* Temporary values.
|
||||||
|
*
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
|
tmp = {
|
||||||
mounted: false,
|
mounted: false,
|
||||||
change: null,
|
change: null,
|
||||||
resolves: 0,
|
resolves: 0,
|
||||||
updates: 0,
|
updates: 0,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the component first mounts, flush a queued change if one exists.
|
* When the component first mounts, flush a queued change if one exists.
|
||||||
@@ -169,10 +171,7 @@ class Editor extends React.Component {
|
|||||||
* @return {Editor}
|
* @return {Editor}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
resolveController = (plugins = [], schema, commands, queries) => {
|
resolveController = memoizeOne((plugins = [], schema, commands, queries) => {
|
||||||
debug('resolvePlugins', { plugins, schema })
|
|
||||||
this.tmp.resolves++
|
|
||||||
|
|
||||||
// If we've resolved a few times already, and it's exactly in line with
|
// If we've resolved a few times already, and it's exactly in line with
|
||||||
// the updates, then warn the user that they may be doing something wrong.
|
// the updates, then warn the user that they may be doing something wrong.
|
||||||
warning(
|
warning(
|
||||||
@@ -180,10 +179,11 @@ class Editor extends React.Component {
|
|||||||
'A Slate <Editor> component is re-resolving the `plugins`, `schema`, `commands` or `queries` on each update, which leads to poor performance. This is often due to passing in a new references for these props with each render by declaring them inline in your render function. Do not do this! Declare them outside your render function, or memoize them instead.'
|
'A Slate <Editor> component is re-resolving the `plugins`, `schema`, `commands` or `queries` on each update, which leads to poor performance. This is often due to passing in a new references for these props with each render by declaring them inline in your render function. Do not do this! Declare them outside your render function, or memoize them instead.'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.tmp.resolves++
|
||||||
const react = ReactPlugin(this.props)
|
const react = ReactPlugin(this.props)
|
||||||
const attrs = { onChange: this.onControllerChange, plugins: [react] }
|
const attrs = { onChange: this.onControllerChange, plugins: [react] }
|
||||||
this.controller = new Controller(attrs, { editor: this, normalize: false })
|
this.controller = new Controller(attrs, { editor: this, normalize: false })
|
||||||
}
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mimic the API of the `Editor` controller, so that this component instance
|
* Mimic the API of the `Editor` controller, so that this component instance
|
||||||
|
Reference in New Issue
Block a user