Hey there,
I’m trying do figure out what the best way might be to reference a dynamic global state when rendering nodes.
The obvious solution would be to create a truly global state (e.g. window.state
) and then refer to that in the toDOM
callback of my node specs. But that doesn’t seem like a very clean way to do this. On the other hand, building a view plugin that iterates through the dom and applies the default attributes on each update might affect performance too much.
Another idea I had was storing the state in the editor state, but there seems to be no way to access that state from toDom
either.
To make it a bit clearer what I’m trying to accomplish:
- I have a schema with a bunch of node types (e. g.
my-node-type
) - I have a state that contains default attrs per node type (e.g.
{"my-node-type": {"background": "blue"}
). - I want to be able to use this state in the
toDom
callback - I want to be able to modify the state and then have that reflected in the affected nodes
Thank you in advance for any pointers!