You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/defining-state.md
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,10 @@ export const state = {
113
113
{% endtab %}
114
114
{% endtabs %}
115
115
116
+
{% hint style="warning" %}
117
+
It is import that you do **NOT** use arrow functions on your methods. The reason is that this binds the context of the method to the instance itself, meaning that Overmind is unable to proxy access and allow you to do tracked mutations
118
+
{% endhint %}
119
+
116
120
You can now use this instance as normal and of course create new ones.
If your transition runs asynchronously you should return the transition to ensure that the action execution is tracked
418
+
{% hint style="warning" %}
419
+
There are two important rules for predictable transitions:
420
+
421
+
1. The transition should be **returned** if the logic or logic runs asynchronously. This is the same as with actions in general
422
+
2. Only **synchronous** transitions can mutate the state, any async mutation will throw an error
416
423
{% endhint %}
417
424
418
425
What is important to realize here is that our logic is separated into **allowable** transitions. That means when we are waiting for the user on **line 4** and some other logic has changed the state to **unauthenticated** in the meantime, the user will not be set, as the **authenticated** transition is now not possible. This is what state machines do. They group logic into states that are allowed to run, preventing invalid logic to run.
0 commit comments