Hi all,
I have a rails model that’s translated to model definition like this:
export default DS.Model.extend({
name: DS.attr('string'),
settings: DS.attr(), // in rails, its a JSON object
tags: DS.attr(), // in rails its again an Array object, which actually models a "set"
..
});
To make it easier to work with these attributes, I created special transfroms that converts settings into a special object and tags into a set
.
However, when I want to update the attributes in settings, or add/remove items from tags, I always had to copy the original object, then update, and finally replace the original with the newly modified object. This way dirty tracking works. However, is there a way for me to update attributes or add/remove objects in place and still trigger dirty? And if there’s an API to mark things dirty, how would rollback work? Generally are there api where I can implement dirty tracking? Ideally what I would like to is the following
user = User.create();
// user.get('isDirty') === false; user.get('settings.isAwesome') === false;
user.get('settings').set('isAwesome', true);
// user.get('isDirty') === true; user.get('settings.isAwesome') === false;
user.rollback();
// user.get('isDirty') === false; user.get('settings.isAwesome') === false;
Any thoughts?