-
I was surprised to get the error that I was changing an observable outside of an action when calling .clear() on an observable array. Is there a reason that all the methods which affect an observable array aren't already wrapped in an action? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For the same reason, why assigments (eg // Consider you forget to apply action here,
// this wouldn't warn:
doSomething() {
this.array.splice();
this.array.clear();
this.map.set("", "");
} It's not about whether it's an assigment or method call, any of these could represent individual and complete operation. It's kinda arbitrary decision to not consider these as "self-sufficent", but it allows us to detect missing batch in majority/lots/many/(you tell me) cases. It's not ideal though, following should ideally warn as well, but it won't: doSomething() {
this.action1();
this.action2();
} Note the internal logic of these methods is always batched, no matter whether it's called from within an action or not. |
Beta Was this translation helpful? Give feedback.
For the same reason, why assigments (eg
o.foo = 5
) aren't wrapped in action:It's not about whether it's an assigment or method call, any of these could represent individual and complete operation. It's kinda arbitrary decision to not consider these as "self-sufficent", but it allows us to detect missing batch in majority/lots/many/(you tell me) cases. It's not ideal though, following should ideally warn as well, but it won't:
Note the internal logic of these methods is always batche…