Closed kingpalethe closed 3 years ago
it should work... I'll create a unit test later and check
BTW are you adding the new item through a model action?
Ah, thanks for that, yes, the issue was that I was doing document.items.push(item)
in a modelAction
... but a modelAction
on another class, somewhere else in the tree. I just moved the document.items.push(item)
into the Document
class, so it looks like this.items.push(item)
, and now the behavior works as expected. Thanks!
Thanks for this fantastic library.
I've been experimenting with UndoMiddleware, https://mobx-keystone.js.org/actionMiddlewares/undoMiddleware
Which is working quite well, but I'm struggling with a strategy for how to use it for child nodes.
Here's an example.
I have a PARENT class, "Document":
and a CHILD class, "Item":
I am finding that whenever I make changes to
document.title
, then I can find thatundoManager.canRedo
returnstrue
, and I can undo changes to thedocument
withundoManager.undo()
.Similarly, if a CHILD
item
has already been added to thedocument.items
array, then changes to the item, for example, changes toitem.text
, also generate a "patch" such that I can undo changes to thatitem
.HOWEVER, I am finding that when adding a NEW child
Item
to thedocument.items
array, a "patch" is not generated, and I can't undo or redo that change. To be clear: My expected behavior is that, assuming aDocument
with0
items
, after making a NEWItem
, such thatdocument.items.length
becomes1
, I could then userundo
, anddocuments.items.length
would be reduced to 0.What would you suggest I do here? I do see
onChildAttachedToTarget
... https://mobx-keystone.js.org/treeLikeStructure#onchildattachedtotarget---object-fn-child-object----void--void-options--deep-boolean-fireforcurrentchildren-boolean--rundetachdisposers-boolean--void ... and I am wondering if I should somehow try to manually trigger a new patch here?thanks