Last active
December 12, 2015 08:08
-
-
Save wagenet/4741222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DS.Adapter.registerTransform('object', { | |
serialize: function(obj) { return obj; }, | |
deserialize: function(obj) { return obj; } | |
}); | |
MyApp.MyModel = DS.Model.extend({ | |
location: DS.attr('object') | |
}); | |
var model = MyApp.Model.createRecord({ location: { lat: 123, lng: 456 } }); | |
model.save(); | |
model.set('location.lat', 789); | |
model.get('isDirty'); // false | |
// Normally this happens automatically, but in this case you're setting the contents of an object so Ember Data doesn't see the | |
model.attributeWillChange(model, 'location'); | |
model.set('location.lat', 789); | |
// Paired with above | |
model.attributeDidChange(model, 'location'); | |
model.get('isDirty'); // true |
Great!
Whoops, made a mistake here. Going to update.
It's actually worth seeing if, instead of calling attributeWillChange
and attributeDidChange
, if just resetting location to itself works, i.e. model.set('location', model.get('location'))
. I'm not sure that this alternative will work though since Ember Data might not think it was an actual change since the object is the same.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man!