ember-buffered-proxy icon indicating copy to clipboard operation
ember-buffered-proxy copied to clipboard

Allow value equality checker to be overridden

Open HeroicEric opened this issue 9 years ago • 5 comments

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 avatar Feb 26 '16 02:02 HeroicEric

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.

blimmer avatar Jun 01 '16 03:06 blimmer

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

I updated this with some docs and renamed the function.

HeroicEric avatar Dec 01 '16 15:12 HeroicEric

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.

blimmer avatar Dec 02 '16 17:12 blimmer

@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?

HeroicEric avatar Dec 02 '16 17:12 HeroicEric

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.

blimmer avatar Dec 02 '16 17:12 blimmer