The current crop of browser based text editors are difficult to integrate into websites that use state containers - such as Redux, Elm, and React's setState
- in a satisfactory way. In a react context we would ideally like to give the editor component a value attribute and update the attribute ourselves, allowing the changes to flow back down to the editor which can then re-render. The editor can maintain a mutable text buffer in its internal state for performance reasons, but as long as its methods are bug free this should look no different to an immutable, state-free component to an outside component.
First let's look at what the initial state of such an editor, with an empty buffer and undo history, would look like assuming we are using immutable.js to maintain state:
{
historyCursor: null
history: List([])