-
-
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
feat(mobx): add support for AbortSignal for reaction
, autorun
and sync when
#3727
Conversation
🦋 Changeset detectedLatest commit: 43e0cfe 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 |
I don't understand why all of a sudden the test failed when I added the changelog... |
What's the use case? |
cleaning up reaction when unmounting In our app when we exit the page we want to abort all pending requests and clean the store, we abort all the requests using current workaround: clearAC.signal.addEventListener(
'abort',
reaction(
() => something,
myFn,
),
{
once: true
}
); |
I see, thank you. |
docs/reactions.md
Outdated
An AbortSignal object instance | ||
for `when` allows you to abort waiting for the reaction via an AbortController. This will also cause the returned promise to reject with an error "WHEN_ABORTED". This option is ignored when using an effect function, and only applies with the promised based version. | ||
for `autorun` and `reaction` allow you to dispose the reaction via the AbortController. |
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.
Replace with
An AbortSignal object instance; can be used as an alternative method for disposal.<br>
`when`: This option is available only for the promise based version. When aborted, the promise rejects with the "WHEN_ABORTED" error.
Feel free to fix grammar or typos if necessary.
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.
When reading:
when
: This option is available only
it seems like it's only for when
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.
You mean like the whole thing? Btw when
delegates to autorun
, can't we now support the non-promise based version as well?
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.
you are right, adding support
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.
done, the non-promised version won't throw an error as it won't get caught...
reaction
and autorun
reaction
, autorun
and sync when
Looks good, thank you! |
thank you!! hope to contribute soon! |
Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatedyarn mobx test:performance
)Performance output
Before:
After: