ember-buffered-proxy
ember-buffered-proxy copied to clipboard
Allow value equality checker to be overridden
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.
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.
Sorry for letting this linger for so long but I need it again 😄
I updated this with some docs and renamed the function.
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 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?
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.