Created
July 12, 2015 22:24
-
-
Save Keeo/37cd5a31efd7c73da166 to your computer and use it in GitHub Desktop.
Ember serializer fn to save only dirty properties
This file contains hidden or 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
// 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