How best to "listen" to transactions?

What’s the best way to “listen” to transactions? Basically, I want to inspect the transaction, and based on what it is (e.g. using contentChanged or getMeta) perform certain actions (server API requests, etc.)

I don’t want to do anything custom to how the transaction is actually dispatched, I only want to inspect it.

What I’ve tried doing so far is to supply a dispatchTransaction function that does the inspections on the tr and then applies the transaction in the “default” way, binding this to the EditorView and calling at the end of dispatchTransaction:

this.updateState(this.state.apply(tr))

This worked well enough, until I tried to use the ProseMirror Dev Tools which apparently interfere with my `this binding.

This led me to wonder, is there a better way to listen in on all transactions if I have no need to modify how they’re dispatched?

Or, if dispatchTransaction is the only way, is there a better way to implement “default” dispatch behavior than binding the EditorView to this?

1 Like

That sounds like a bug in the dev tools—it would make sense to report that there.

There isn’t currently a better way to do this (though I agree it might make sense to provide one).

I haven’t gotten to this point in my usage of ProseMirror to know if I need this, but I hope you share when you figure out a solution!