The Ember docs explain the Transform functionality with an example. I have a problem to understand one thing.
Question:
Why they use Ember.create() within deserialize function instead only the pure object?
Like return { x: value[0], y: value[1] } instead Ember.create({ x: value[0], y: value[1] }).
What are the benefits to use Ember.create() (especially in the Transform function)?
App.CoordinatePointTransform = DS.Transform.extend({
serialize: function(value) {
return [value.get('x'), value.get('y')];
},
deserialize: function(value) {
return Ember.create({ x: value[0], y: value[1] });
}
});
App.Cursor = DS.Model.extend({
position: DS.attr('coordinatePoint')
});
It creates a new instances with those properties (essentially a different copy). In this case it's doing nothing of consequence and could just be the hash.
Identical to Object.create(). Implements if not available natively.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.