Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert model changes without Ember-Data

I have a model created from a JSON object that has many properties bound to the UI (a preferences panel). I would like to allow the user to update their preferences, but I also need a way for them to revert their changes to the model after they've made changes to the UI.

I see many examples using Ember-Data, but we're not using that; Nor do I see any obvious pattern/methods in the Ember docs. Is there a commonly used pattern to achieve 'rollback' on a model without Ember-Data?

like image 978
Geoff Avatar asked Feb 04 '26 09:02

Geoff


1 Answers

It really depends on how your models are structured. I wrote my own Ember persistence library and I made every property a computed property (like Ember-Data). From there, I had two hashes in each model, oldProperties and newProperties. I use the two in tandem to read, and only write to newProperties. That way I can always restore to oldProperties if necessary.

The bottom line is that Ember itself doesn't store old property values for you. You'll have write your own custom logic to store the old values and restore them when you need.

like image 107
GJK Avatar answered Feb 07 '26 02:02

GJK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!