Skip to content

Instantly share code, notes, and snippets.

@pixelhandler
Last active October 3, 2016 06:54
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pixelhandler/10510984 to your computer and use it in GitHub Desktop.
Save pixelhandler/10510984 to your computer and use it in GitHub Desktop.
Raw object and array tranforms for Ember Data
/*
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();
}
}
});
@NuckChorris
Copy link

For anyone who comes here and wants it for Ember-CLI, I ported it for you: https://gist.github.com/NuckChorris/927d7d4ba757abd26b30

@spectras
Copy link

Am I right in assuming this will fail to mark the model as dirty if the array gets updated?

@coryondemand
Copy link

@spectras you are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment