Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions addon/mixins/copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
Logger,
guidFor,
isEmpty,
runInDebug
runInDebug,
canInvoke
} = Ember;

const {
Expand Down Expand Up @@ -137,12 +138,21 @@ export default Ember.Mixin.create({
!PRIMITIVE_TYPES.includes(type)
) {
let value = this.get(name);
let transform = getTransform(this, type, _meta);

// Run the transform on the value. This should guarantee that we get
// a new instance.
value = transform.serialize(value, attributeOptions);
value = transform.deserialize(value, attributeOptions);
if (canInvoke(value, 'copy')) {
// "value" is an Ember.Object using the Ember.Copyable API (if you use
// the "Ember Data Model Fragments" addon and "value" is a fragment or
// if use your own serializer where you deserialize a value to an
// Ember.Object using this Ember.Copyable API)
value = value.copy(deep);
} else {
let transform = getTransform(this, type, _meta);

// Run the transform on the value. This should guarantee that we get
// a new instance.
value = transform.serialize(value, attributeOptions);
value = transform.deserialize(value, attributeOptions);
}

attrs[name] = value;
} else {
Expand Down