-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Ember.Copyable mixin features if present #6
Use Ember.Copyable mixin features if present #6
Conversation
@offirgolan Any response? Do not hesitate to contact me if you need further informations, etc. Thank you. |
addon/mixins/copyable.js
Outdated
// a new instance. | ||
value = transform.serialize(value, attributeOptions); | ||
value = transform.deserialize(value, attributeOptions); | ||
if ( |
There was a problem hiding this comment.
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')) { ... }
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
addon/mixins/copyable.js
Outdated
(Ember.typeOf(value) === 'instance') && | ||
(Ember.typeOf(value.copy) === 'function') | ||
) { | ||
value = value.copy(deep); |
There was a problem hiding this comment.
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.
@offirgolan Hello. I made the changes. Is it OK for you? Thanks. |
@mpirio thanks for taking the time to put this together! 😸 |
Hello,
I use ember-data-model-fragments and I had a problem when using ember-data-copyable (ember-data-model-fragments use own type but this could be the same for other addons) so i sent you this first PR.
But this first PR is not enough to support ember-data-model-fragments. A fragment extends DS.Model and when ember-data-copyable (de)serialize to get a new value instance, it's should be a DS.Snapshot and not a DS.Model instance which should be passed as argument.
I think it should be better to use
copy
method (cf Ember.Copyable) ifvalue
is an Ember Object instance and if it use Ember.Copyable mixin. So this new PR.What do you think about this proposal? Thanks.