Please clarify how throwing inside subscribe() works
#842
pastelmind
started this conversation in
General
Replies: 1 comment
-
|
In the valtio mental model, you can't stop the mutation. subscribe is called to notify that the mutation happened after the mutation. I think we should say, throwing in the subscription callbacks leads to an unexpected behavior. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently,
subscribe()consumes errors thrown inside the callback:This is because
subscribe()does not handle rejections here:valtio/src/vanilla.ts
Lines 378 to 383 in 26caa88
If a synchronously subscribed callback throws, it does cause the offending mutation to throw. But it will also cause all subscribers registered after it to be skipped:
This is because all subscribers are invoked synchronously here:
valtio/src/vanilla.ts
Line 176 in 26caa88
I just want to know if this is intended. I don't care if it is fixed or kept this way. But it would be beneficial if this behavior is documented somewhere.
Beta Was this translation helpful? Give feedback.
All reactions