Skip to content
Merged
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions addon/mixins/copyable.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,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 (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be

if (canInvoke(value, 'copy')) { ... }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can use Ember.canInvoke. But i would like to be sure value is an Ember Object which extends Ember.Copyable mixin and so, value#copy() is really the method that copy this object (and not a method to do anything else). I do not know how to do... Perhaps do you know?

Copy link
Copy Markdown
Contributor Author

@mpirio mpirio Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@offirgolan Any response ? I will make the change but Ember.canInvoke is a private method. We should use Ember.tryInvoke method.

(Ember.typeOf(value) === 'instance') &&
(Ember.typeOf(value.copy) === 'function')
) {
value = value.copy(deep);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here as to how we can get to this point.

}
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