-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update props atomically and consistently
Whether the editor state is controlled or uncontrolled, update all props atomically and only in a layout effect after rendering. - Put uncontrolled state into a state hook. The default dispatch can use this hook to update the editor state so that view updates always occur in a layout effect after a render cycle, even with uncontrolled state. - Type the components and hooks to account for passing both defaultState and state. Handle this in the same way that React itself does, writing a warning to the console on the first occurrence, such that users that do not use TypeScript still get some guidance. - Merge the layout effects that update the view so that all of the props of the view get updated simultaneously. Otherwise, any view props that may close over external state, such as decorations, may be out of date during the update of non-state props, which can cause errors. - Push all logic from the inner ProseMirror component into the hook so that all props beyond the base ProseMirror editor props get handled in one place. - Inline the inner component into the main ProseMirror component module. Name the component simply "Editor" to align with its purpose of owning the editor view and providing the editor context. - Give the contexts display names so that their purpose is clearer when viewing them in React development tools. - Use "state" in all examples, instead of "editorState", for simplicity. This library is not Redux and software developers are used to handling naming collisions, if they occur. Redux users are used to seeing React examples that use the state hook and knowing that it is different from Redux state. ProseMirror state is similar in this way.
- Loading branch information
Showing
9 changed files
with
190 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.