-
According to docs, reactions should be used sparingly. However, it is not clear why and what's the reason for that. I have checked existing issues and discussions but didn't find a clear-cut answer. It seems reactions are really convenient when you have internal class flows that depend on number of properties. Let's say a class that is responsible for generating time table, where number of days, starting day, starting hour, ending hour, etc. are all user-configurable. By configuring reactions for each of those properties I can ensur a consistent state of data. However, according to docs, it's not best practise to do so? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can't. All reactions wait until your system is already in a consistent state (that's when action is finished): autorun(() => this.b = this.a + 1)
@action doSomething() {
this.a + 1;
console.log(this.b) // inconsistent, not updated yet
} Also there is no guaranteed order: autorun(() => this.b = this.a + 1)
autorun(() => this.c = this.b + 1)
// these can run in whathever order Lastly it (arguably) leads to a bad architecture, don't want to go into lengthy details, just a simple example. Imagine you wanna find out what happens when you click on something: @action onClick() {
this.a = 5;
} Ok, so I also tried to make some points here, if you're interested: |
Beta Was this translation helpful? Give feedback.
You can't. All reactions wait until your system is already in a consistent state (that's when action is finished):
Also there is no guaranteed order:
Lastly it (arguably) leads to a bad architecture, don't want to go into lengthy details, just a simple example. Imagine you wanna find out what happens when you click on something:
Ok, so
a
changes to 5, simple ... except if you use…