-
-
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
using ts disposable #3841
using ts disposable #3841
Conversation
🦋 Changeset detectedLatest commit: 3d1b0e5 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 |
@vovsemenv Thank you, could you add some unit tests? |
@mweststrate @urugator I think having a utility like this is a good option, as the other ways to modify code asynchronously are far from ideal:
|
@kubk added test, please approve ci run |
I am not strictly opposed, but I think it has some negatives, while I am not sure about benefits.
Isn't it almost the same? async action() {
using _ = _action();
this.x = 1
await fetch()
{
using _ = _action();
this.x = 1
}
await fetch()
{
using _ = _action();
this.x = 1;
}
} Am I missing something? |
0b7baaf
to
3d1b0e5
Compare
@urugator Valid points have been brought up 👍 Yes, the requirement of having a variable leads to issues with ESLint. @vovsemenv are you interested in moving it to userland as a separate NPM package? It seems like the solution has its own drawbacks and can't be added to the core. |
It is kinda cool! But a crucial design question is still open I think; transactions in MobX are always concluded synchronously (otherwise it might interfere with concurrent transactions or 'block' updating entirely). So given something like:
I'd expect the output to be:
But I think that will be the case with the current implementation, as the updates will only appear entirely at the end, and the output is just The reason why that is important, is that a) transactions are global in MobX and b) we don't want to block things like react components updating in an async way, as in that case the app might freeze if you are doing a async transaction that contains a network request or so. |
You're correct. I thought there is a difference between async action() {
{
using _ = _action();
this.x = 1
}
await fetch()
{
using _ = _action();
this.x = 1
}
await fetch()
{
using _ = _action();
this.x = 1;
}
} In principle you can combine it with @action
async action() {
this.x = 1;
await fetch()
{
using _ = _action();
this.x = 1
}
await fetch()
{
using _ = _action();
this.x = 1;
}
} |
Closing this PR as there seems sadly no way to make this work for async boundaries, and without it will just be another way (not particularly easier or shorter) of doing |
implements #3840
Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatedyarn mobx test:performance
)