In Ember-CLI, transforms are located in app/transforms/name.js
// app/transforms/array.js | |
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
export default DS.Transform.extend({ | |
deserialize: function(value) { | |
if (Ember.isArray(value)) { | |
return Ember.A(value); | |
} else { | |
return Ember.A(); | |
} | |
}, | |
serialize: function(value) { | |
if (Ember.isArray(value)) { | |
return Ember.A(value); | |
} else { | |
return Ember.A(); | |
} | |
} | |
}); |
// app/transforms/object.js | |
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
export default DS.Transform.extend({ | |
deserialize: function(value) { | |
if (!Ember.$.isPlainObject(value)) { | |
return {}; | |
} else { | |
return value; | |
} | |
}, | |
serialize: function(value) { | |
if (!Ember.$.isPlainObject(value)) { | |
return {}; | |
} else { | |
return value; | |
} | |
} | |
}); |
This comment has been minimized.
This comment has been minimized.
tmquinn
commented
Apr 10, 2015
the real trick of this would be accurate dirty checking |
This comment has been minimized.
This comment has been minimized.
billpull
commented
Jul 15, 2015
@seanpdoyle |
This comment has been minimized.
This comment has been minimized.
jessepinho
commented
Aug 16, 2015
@billpull Point is, if you don't specify a type in your call to |
This comment has been minimized.
This comment has been minimized.
cloke
commented
Jul 6, 2017
Sort of late to the conversation, but I find these transforms useful if you want to use defaultValue with the attr. Otherwise you are correct, the objects just pass through when no attributes type is passed in. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
seanpdoyle commentedApr 2, 2015
Couldn't these transforms be replaced with calls to
DS.attr()
(type string intentionally omitted)?http://emberjs.com/api/data/classes/DS.html#method_attr