Action whenever a certain node type is removed from the doc

I’m looking to run some logic whenever a certain node type is removed from the doc. I know I could implement a plugin that listens to all the transactions and deduce from the steps whether a node of that type is removed in a given transaction, but this particular node type already has a node view, so I’m wondering if I could just put the logic in the node views destroy method? Are there any downsides to this or any cases where this wouldn’t be called?

destroy should be called for each node that’s removed from the document, but may also be called when a node’s context changes (when the update logic doesn’t manage to reuse it and ends up recreating the node view) or when the editor is destroyed. Also, you shouldn’t dispatch transactions or otherwise update the view from a destroy method, since it’s called in the middle of an update.

1 Like

Ah, I wasn’t aware about it being called when the editor is destroyed. I’ve found a better way. Thanks and thanks for the additional info!