Is it possible to subscribe to view editable flag changing?

Hi all,

Is anyone aware of a way to subscribe to changes on the editable property of the view?

I am using NodeViews to render checkboxes on task list items, and I would like to disable those checkboxes when view editable property is changed to false.

Is there any event or plugin solution I could use to achieve this behaviour?

Thanks.

On every update (say, in a plugin view update function), check view.editable and respond to it if it changed.

So does that mean I would need to wait for an arbitrary amount of time for a transaction to dispatched?

The editable flag is only going to change at a time where a view update happens anyway, so there’s no waiting happening.

Cool, I can see how the PluginView update function is called, but the update handler on my NodeView isn’t called.

Is there something I’ve missed here?

Glitch example: Glitch :・゚✧

I never claimed the update handler on a node view would be called. It won’t be.

Apologies I didn’t mean that to sound acustatory.

I just meant do you have any suggestions for how i could trigger a NodeView update?

Node views get updated when the node changes or when the decorations on it change, otherwise they are entirely inert.

Ok thanks. I think I will search the doc for node types I know have a NodeView and trigger a useless attribute update. See where that gets me

@whawker Please share the doc if you can find it for node types. Thanks in advance!

1 Like

The better pattern, rather than “subscribing” to view.editable, will just be to hold a piece of boolean state editable outside prosemirror, and look at that in your node view and also in the view (and call view.update({editable: false}) when it changes). That way, they will be in “sync”.

Rather than trying to “sync” pieces of state together, it usually might be better to just lift that state up in your tree.