I am trying to organize my plugin’s data flow in unidirectional fashion, like so:
- In handleKeyDown, I convert key presses to plugin actions, where I define a plugin action to be the payload of a transaction’s meta.
StateFieldapply, I extract the action from the transaction and use it to reduce my plugin’s state, obtaining a new plugin state.
PluginSpecview, I update the plugin-managed view with the plugin state from step 2.
All this works fine provided that the plugin is only interested in updating its own state. What I can’t figure out is how to update editor state within the separation of responsibilities outlined above. Specifically, what I would like to be able to do, is be able to emit editor state updates from within step 2 above, which I think is the cleanest place to do this in. But
apply receives no reference to the view, which I would need in order to request an editor state update.
I suspect that the above scheme, heavily informed by Redux, may be unnatural to the way ProseMirror plugins are intended to work, but I’m not quite sure what that is. Any suggestions for improvement would be appreciated.