Last active
October 3, 2016 06:54
-
-
Save pixelhandler/10510984 to your computer and use it in GitHub Desktop.
Raw object and array tranforms for Ember Data
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
/* | |
DS.attr('object') | |
*/ | |
App.ObjectTransform = DS.Transform.extend({ | |
deserialize: function(value) { | |
if (!$.isPlainObject(value)) { | |
return {}; | |
} else { | |
return value; | |
} | |
}, | |
serialize: function(value) { | |
if (!$.isPlainObject(value)) { | |
return {}; | |
} else { | |
return value; | |
} | |
} | |
}); | |
/* | |
DS.attr('array') | |
*/ | |
App.ArrayTransform = DS.Transform.extend({ | |
deserialize: function(value) { | |
if (Ember.isArray(value)) { | |
return Em.A(value); | |
} else { | |
return Em.A(); | |
} | |
}, | |
serialize: function(value) { | |
if (Ember.isArray(value)) { | |
return Em.A(value); | |
} else { | |
return Em.A(); | |
} | |
} | |
}); |
Am I right in assuming this will fail to mark the model as dirty if the array gets updated?
@spectras you are correct.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone who comes here and wants it for Ember-CLI, I ported it for you: https://gist.github.com/NuckChorris/927d7d4ba757abd26b30