-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Computed / Reaction comparer #951
Conversation
EDIT: I seem to have fixed the build issue described below by removing the Also, I've now added the Original: WIP because of a couple of build / test issues which I'd appreciate help with: I was hoping to change the signature of // from...
function createComputedDecorator(compareStructural: boolean)
// to...
function createComputedDecorator(equals: IEqualsComparer<any>) and therefore change the following lines: // from...
const computedDecorator = createComputedDecorator(false);
const computedStructDecorator = createComputedDecorator(true);
// to...
const computedDecorator = createComputedDecorator(defaultComparer);
const computedStructDecorator = createComputedDecorator(structuralComparer); However, I can't because for some reason the comparers are Any advice on what the problem here might be? Also, I want to add a function similar to const isSameid = (a, b) => a.id === b.id;
class Foo {
@computed.equals(isSameid ) get selected() {
...
}
} I'll do this once I've solved my build problem, but any comments on the name of this would be appreciated (or are you happy with 'equals'?). I'll sort the docs, tests, etc. once the above are sorted. Any comments welcome! |
@mweststrate I started writing some tests for this, and come up with something I'd like input on: Do we think that I should hide away the change detection for the first value, and from/to CaughtException such that:
As such, there won't be any 'surprising' values being passed to the comparer function; if you have a basic computed property like so: get time() {
return { hour: this.hour, minute: this.minute }
} I'll know that if I add an const sameTime = (a, b) => a.hour === b.hour && a.minute === b.minute; i.e. i don't have to check if (The latest commit now has this behaviour, and is covered by this test) |
…nvoked in first case, or from/to caught exceptions. added tests.
@jamiewinder sorry for not having time earlier to look into this! Imho Circular references in the build process are annoying indeed. I want to move to rollup in the near feature, as that hopefully fixes without blowing the bundle size. In the mean time, if it is still an issue, just let me know and I'll investigate it. Moving imports to top / bottom, or using functions instead of constants (as functions get hoisted but constant assignments not) can often help |
No problem at all, we're all busy! The behaviour of the I've included some tests which I believe covers this for both computed-s and reaction-s. As far as I'm aware, the only things missing is the documentation, which I can do if we're happy with everything else. Thanks. |
@jamiewinder this PR looks great, let's proceed with it! Could you take at the the following points:
Thanks a lot so far! I think this is a great PR :) |
I've made the code changes (updated to master, moved comparers to a namespace, non-decorator tests). I can't seem to figure out why the CI is now failing?
I'll keep looking, but can you spot anything obvious? |
This means that rollup didn't properly resolve ciruclar dependencies, and
some inheritance is failing because the base class is not defined. Usually
this needs to be fixed by moving some imports a round, for example to the
bottom of a file
Op do 29 jun. 2017 om 11:47 schreef jamiewinder <[email protected]>:
… I've made the code changes (updated to master, moved comparers to a
namespace, non-decorator tests). I can't seem to figure out why the CI is
now failing?
TypeError: Object prototype may only be an Object or null: undefined
at setPrototypeOf (native)
at r (C:\Projects\GitHub\mobx\lib\mobx.js:2:560)
I'll keep looking, but can you spot anything obvious?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#951 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhKwhrAZON-1RJcBVdswPLhA9ordmks5sI3LBgaJpZM4M-aVJ>
.
|
Thanks for the tip! Seems to be sorted. Only thing left is documentation, which I'll try to update soon. |
Documentation in separate pull request #1084 |
Released as 3.2.1. Thanks! |
Addresses #802 and #943
Allows a custom comparer to be specified on computed values and properties. Useful for situations where the inbuilt identity and structural comparisons aren't sufficient.
This should be completely backwards compatible with the current major version.
Still to do:
@computed.equals(equals: IEqualsComparer)
PR checklist:
gh-pages
branch. Please refer to this PR). For new functionality, at least API.md should be updatednpm run perf
)