[Question] Change observable several times inside Action #762
subzero911
started this conversation in
General
Replies: 1 comment 5 replies
-
@subzero911 I haven't tested it, but how about doing something like this: @action
void foo() {
// I change the Observable and a button turns red
}
@action
void bar() {
// I change the Observable again and button turns back to transparent
}
// without @action
Future<void> optimisticUpdate() {
try {
// I change the Observable and a button turns red
foo();
// I perform a web request
performWebRequest();
} catch (e) {
// If it fails, I change the Observable again and button turns back to transparent
bar();
}
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
An
Action
batches all Observable changes and gives us a final result only.What if I want not to batch changes, and want to rebuild Observer content on every Observable change?
Example - an optimistic update scenario:
It all comes within a single Action.
It's easily achieved with notifyListeners(), but i don't how to do it with MobX.
Beta Was this translation helpful? Give feedback.
All reactions