ember-time-machine icon indicating copy to clipboard operation
ember-time-machine copied to clipboard

setProperties behaviour

Open denzo opened this issue 7 years ago • 2 comments

We have a scenario where one action updates numerous properties on an object.

actions: {

  changeItemType(item, type) {
    setProperties(item, {
      type,
      options: options.findBy('type', type)
    });
  } 

}

When we call item.undo() we would expect all the attributes updates in the action to be reverted but it turns out that each attribute change is recorded as one undo.

Is there currently a way to achieve our requirement?

denzo avatar Nov 10 '17 05:11 denzo

@offirgolan I had a play with your awesome code! And whipped up something that works https://github.com/offirgolan/ember-time-machine/pull/121

The new API is timemachine.beginChanges() and timemachine.endChanges() where you can make as many changes as you want but it will be undone with one step.

denzo avatar Nov 11 '17 02:11 denzo

@offirgolan here's another approach where the undoStack is a collection of changeSets which is essentially an array of Record changes. A bit more neat I think 😉 https://github.com/offirgolan/ember-time-machine/pull/122

denzo avatar Nov 11 '17 06:11 denzo