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

Allow value equality checker to be overridden #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HeroicEric
Copy link

It would be nice if there was a way to override how values are compared inside of setUknownProperty without having to override the whole function.

For example, we're working on an app where we're buffering changes made to an array of POJOs and === doesn't detect equality there like we want it to so we're using _.isEqual from lodash.

This also makes it easy to override how values for a specific key are compared.

I'm not a fan of the function name I used here but I wanted to see if you're open to this possibility before spending any more time on it.

Another option could be using Ember.isEqual, since you can define isEqual for whatever you want, but this would require converting to an Ember.Object, making it a little less flexible.

@HeroicEric HeroicEric changed the title WIP - Allow value equality checker to be overridden Allow value equality checker to be overridden Feb 26, 2016
@@ -114,5 +114,9 @@ export default Ember.Mixin.create({
if (empty(this.buffer)) {
this.set('hasBufferedChanges', false);
}
},

_compareValues(a, b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're intending the consumer to override this in some situations, why did you go with the _ naming convention here?

@blimmer
Copy link
Contributor

blimmer commented Jun 1, 2016

This seems like a totally sane use case @HeroicEric , especially because this implementation strategy won't change the behavior for folks if they don't want / care to know about this. If you'd like to rebase this old branch and write some tests, I think it would be a great addition.

@HeroicEric HeroicEric force-pushed the override-value-comparison branch 3 times, most recently from c1e71b8 to d47b17f Compare November 30, 2016 23:38
@HeroicEric
Copy link
Author

Sorry for letting this linger for so long but I need it again 😄

I updated this with some docs and renamed the function.

@blimmer
Copy link
Contributor

blimmer commented Dec 2, 2016

No problem - this looks great to me and it backwards compatible. cc @lukemelia do you want to have a look and sign off on this? @HeroicEric if I don't hear from Luke in a few days, I can merge.

@HeroicEric
Copy link
Author

@blimmer I just remembered why the function was initially underscored. I thought it might be better in terms of avoiding potentially causing issues with the underlying content having a key with the same name. I think it's probably uncommon to have an isEqual key but it's possible. What do you think?

@blimmer
Copy link
Contributor

blimmer commented Dec 2, 2016

That's a good point, though underscored methods usually indicate don't use this to me.

You could use something less likely to be overridden like 'bufferedProxyIsEqual' or the like.

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.

None yet

2 participants