1
0
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:
Ian Storm Taylor
2018-10-10 09:51:18 -07:00
parent 9c597cf97f
commit 6168ce932e

View File

@@ -70,22 +70,24 @@ 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 = { /**
mounted: false, * Temporary values.
change: null, *
resolves: 0, * @type {Object}
updates: 0, */
}
tmp = {
mounted: false,
change: null,
resolves: 0,
updates: 0,
} }
/** /**
@@ -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