Skip to content

Instantly share code, notes, and snippets.

@sbbitch7
Forked from pixelhandler/transforms.js
Created January 13, 2016 09:22
Show Gist options
  • Save sbbitch7/7b628db9ac42b03216f5 to your computer and use it in GitHub Desktop.
Save sbbitch7/7b628db9ac42b03216f5 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();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment