I have a use case where I’d like to perform some business logic using the updated view after each transaction cycle that had some metadata tag.
I’m looking for the best practice for doing this.
Does the library provide some post-view-update hook?
Equivalently, how can I perform post events operations (e.g. after key-down was finished and the char was added, after a pasted text was added, etc.)
If you want to further manipulate the editor state, use an appendTransaction hook. If you want to do something external, the update method of a plugin view is probably a good place.
In my case, I’d like to perform some operation each time the user is hitting the space key.
I want the space to get into the document but also to let some other plugins handle this if needed - so I’d rather to perform my activities after the document was actually updated.
What will be the recommended approach here? will raising a flag in the appendTransaction and perform my logic in view.update be robust enough?
For that, I’d use a key binding that returns false (so others also run) and schedules an asynchronous action to handle the space press after its native behavior goes through. Make sure you put it before other key bindings in the array of plugins, so that it gets run even if another handler handles space.