Skip to content
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

Merged
merged 2 commits into from
Oct 7, 2017

Conversation

mpirio
Copy link
Contributor

@mpirio mpirio commented Aug 19, 2017

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) if value is an Ember Object instance and if it use Ember.Copyable mixin. So this new PR.

What do you think about this proposal? Thanks.

@mpirio
Copy link
Contributor Author

mpirio commented Sep 4, 2017

@offirgolan Any response? Do not hesitate to contact me if you need further informations, etc. Thank you.

// a new instance.
value = transform.serialize(value, attributeOptions);
value = transform.deserialize(value, attributeOptions);
if (
Copy link
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
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
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
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.

@mpirio
Copy link
Contributor Author

mpirio commented Sep 30, 2017

@offirgolan Hello. I made the changes. Is it OK for you? Thanks.

@offirgolan offirgolan merged commit 9bd182e into offirgolan:master Oct 7, 2017
@offirgolan
Copy link
Owner

@mpirio thanks for taking the time to put this together! 😸

@mpirio mpirio deleted the feature/useEmberCopyableMixin branch October 11, 2017 12:14
@mpirio mpirio mentioned this pull request Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants