How do you handle events, such as button clicks, inside decorations?
For example, if I have a widget that is a button and when it is clicked I want to change its icon and hide some of its parent containers content.
I was able to get the behavior working via the nodeViews (listening the the click action in the container rather than the button itself). But this seems pretty hacky. Another alternative might be listening to custom events in the parent container. But before I do that, is there an equivalent of view.dispatch for decorations or some other recommended way to have the view react to events?
I see here that you passed the dispatch function to the commentUI plugin.
I tried doing the same, but ended up getting an applying a mismatch transaction error, since some decorations were created in the init hook and others in the apply hook and I’m guessing the state transaction can’t differ.
I believe you got around this by separating the commentPlugin and commentUI functionality.
I was wondering if another possibility was, rather than a dispatch function only to the UI plugin, passing the editor instance itself with its view and state.
That works. You’re sharing more information with the plugin than strictly necessary, and it can be a bit awkward to set things up so that the plugin, which has to be created before the state, gets access to the view, but you can do that.