-
-
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
fix #3747 #3748
fix #3747 #3748
Conversation
🦋 Changeset detectedLatest commit: 60d4072 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/mobx/src/core/atom.ts
Outdated
if (globalState.inBatch && this.batchId_ === globalState.batchId) { | ||
// Called from the same batch this atom was created in. | ||
return | ||
if (globalState.inBatch && this.batchId_ !== globalState.batchId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!globalState.inBatch || this.batchId_ !== globalState.batchId
If not in batch mutation always updates version immediately.
If in batch only if it's different.
Btw the state version is currently relevant only for autorun(() => {
// batch id 1
const o = observable.box(0);
autorun(() => {
// This won't run until the outer `autorun` finishes
// batch id 2
o.get();
});
o.set(1); // no point in reporting change to nested autorun, it's not subscribed to `o` yet.
}) If there is a case, that I am not aware of, where that isn't true, then there is a problem. |
Heh, the fix ends in state |
packages/mobx/src/core/atom.ts
Outdated
@@ -68,7 +68,7 @@ export class Atom implements IAtom { | |||
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate. | |||
*/ | |||
public reportChanged() { | |||
if (globalState.inBatch && this.batchId_ !== globalState.batchId) { | |||
if (!globalState.inBatch && this.batchId_ !== globalState.batchId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& => ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh lol I should try to read before copy pasting next time. That fixes the test. However, the autorun doesn't initially reschedule itself (see the comment in the test), I think this used to be the case in the past, or am I mistaken here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this used to be the case in the past, or am I mistaken here?
I don't know if this was the case in the past, but it wasn't the case when I wrote this test, otherwise there wouldn't be that extra o.x++
outside the autorun to nudge it and it would fail, because o.x
would end up being 6. I think I was probably a bit surprised as well when writing it. However, if there is some problem here, it was there before introducing this state version business.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check, I'll land this, as it sounds that might be a separate issue, if it is one.
Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatedyarn mobx test:performance
)