What code can you run inside effect transactions? #60
-
When running a transaction, can I run normal code? I mean code that can conditionally call a setter function. If no setter is called, will the transaction trigger a rebuild? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes. Don't run anything that can throw an exception though--that is not supported ATM.
container.runTransaction(() {
final (_, setState) = container.read(someStateGetterSetterCapsule);
setState(1234);
final (getState, _) = container.read(someStateGetterSetterCapsule);
// invoking getState here will return 1234, despite the rebuild not happening until later!
); This is another one of those issues that isn't an issue in Rust. It's also a symptom of how Dart works and how I designed the API around that. I suppose I might be able to do a fix where you pass any side effect state mutations inside of a call to rebuild like is done in Rust without any breaking changes--that is an idea that might be worth exploring. Edit: #61
No, only capsules that triggered a rebuild during the transaction will actually rebuild. |
Beta Was this translation helpful? Give feedback.
Yes. Don't run anything that can throw an exception though--that is not supported ATM.
container.read
,container.runTransaction
, and side effect rebuilds are all fair game. Just be a little careful that the data that youcontainer.read
is actually immutable; i.e., imagine the following:This is another one of those issues that isn't an issue in Rust.…