Я использую оболочку Reaction-draft-wysiwyg для Draft.js.
На странице у меня есть несколько экземпляров компонента Editor.
У меня проблема с медленным / медленным обновлением интерфейса редактора (обработчик событий onChange
).
Может быть, это какой-то намек, я получаю много предупреждений в консоли [Violation] 'input' handler took <N>msA
.
![Screenshot from 2019-03-29 22-02-43](https://user-images.githubusercontent.com/22525941/55265107-aa62e980-526e-11e9-847d-5141dcfcea71.png)
Моя настройка:
- реагируют-шаблонный
- реагировать-проект-WYSIWYG
- перевождь
- перевождь-сага
- Reselect
Я диспетчеризирую действие, чтобы обработать состояние редактора, измените его обработкой redux-saga.
Saga проверит наличие нового контента и обновит магазин.
export function* handleOnEditorStateChange({ editorState, nameSpace }) {
const actualEditorState = yield select(selectAllEditorsContent());
const editorIndexToUpdate = actualEditorState.findIndex(
editors => editors.name === nameSpace,
);
const currentContent = actualEditorState[
editorIndexToUpdate
].state.getCurrentContent();
const newContent = editorState.getCurrentContent();
const hasEditorNewContent = newContent !== currentContent;
if (hasEditorNewContent) {
const updatedEditorState = [...actualEditorState];
updatedEditorState[editorIndexToUpdate].state = editorState;
yield put(storeEditorStateAction(updatedEditorState));
}
}
Мое избыточное состояние выглядит так:
...
editors: [
{
name: 'editor1',
label: 'Editor 1',
state: {... _immutable - draftjs }
},
{
name: 'editor2',
label: 'Editor 2',
state: {... _immutable - draftjs }
},
]
...
Разбавление:
...
case STORE_EDITOR_STATE: {
const { content } = action;
return state.set('editors', content);
}
...