Skip to content

Instantly share code, notes, and snippets.

@Keeo
Created July 12, 2015 22:24
Show Gist options
  • Save Keeo/37cd5a31efd7c73da166 to your computer and use it in GitHub Desktop.
Save Keeo/37cd5a31efd7c73da166 to your computer and use it in GitHub Desktop.
Ember serializer fn to save only dirty properties
// original thread: http://discuss.emberjs.com/t/dirt-tracking-with-ember-data-only-save-dirty-properties/4191/22
// made by Glavin001
serializeAttribute: function(snapshot, json, key, attributes) {
// Check if new record
if (snapshot.get('isNew')) {
// Is new
return this._super(snapshot, json, key, attributes);
} else {
// Check if current attribute is in flight
let attrKey = '_internalModel._inFlightAttributes.'+key;
if (snapshot.get(attrKey) != null) {
// Attribute is dirty
return this._super(snapshot, json, key, attributes);
} else {
// Attribute is not dirty, not stored in inFlightAttributes
// Ignore this attribute
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment