So right now I have a hashTag node type, and every time a hashTag is created and deleted, I’d like to insert/delete the corresponding database entry.
After looking around, I added a dispatchTransaction callback for the view, which passes in a Transaction.
In Prosemirror Dev Tool, I seemed to have access to the node through tx > steps > 0 > slice > content > content > hashTag node. But in code (TypeScript), I can’t seem to access slice on the Step. I tried converting it to ReplaceStep to no avail. Is there a way to get access, or am I doing it wrong?
Or maybe taking a step back, am I approaching this problem correctly?
Not all step types have slices. You could do an s instanceof ReplaceStep || s instanceof ReplaceAroundStep check to narrow the type, or you could iterate over the parts of the new doc covered by the step (with the step map’s forEach method).
But I guess to detect node removal, I still need to compare docs right? (I couldn’t find any info in the slice about what node was removed) So for that would the last doc in tr.docs give me a point of comparison?