I need to update node attributes within the apply function of a decoration widget plugin (in my case the node’s updated height), but I am wondering about the required process. I have the transform field from the app (apply(tr, oldDecorationSet, oldState, newState) {…}) and am cycling through the nodes with the tr.doc.descendants((node, pos) => {} loop, and have considered adding the following line:
tr.setNodeMarkup(pos, null, { …node.attrs, height: newHeight });
If I just call that in the loop, will the node get updated and then the updated node returned when the doc is updated after the plugin execution is completed?
I have seen several sample code snippets from Google searches, and they usually add a dispatch call to get PM to process the markup change, but in my case I am already in a plugin apply function that is passed a transform object in the apply function. In fact, all of the sample code snippets dispatch transactions to update the field, making me wonder if any changes I might make to nodes in my plugin might not be retained when the plugin code completes execution.
Any advice would be appreciated, my intent is that for nodes with a node attr of undefined, I recalc the height and then need to save it (to avoid future height calculations for that node), right in the code where I am cycling through all the transform doc nodes in the apply function. Seems simple, but obviously I want things to remain immutable and stable.