Extended State for hisma #16
-
As I know, in the document UML State Machine has its Extended State to store the data which the application needs to show on UI for the user. Do you have any plans for it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
First of all thank you for your question. This is one of the areas where I did the minimum effort implementation that satisfies my initial needs for my apps but I am eager to have conversation about how to do it better. Let's cover first what is there already. Hisma state machines have a dynamic type attribute called fb_auth_hisma_example is an example Flutter app that demonstrates how an existing Hisma state machine can be used as the engine for a Flutter app. The machine is fb_auth_hisma that defines a hierarchical state machine for Firebase authentication. One simple example of machine.data usage is in failed_signin_dialog.dart When login fails an error message (that is coming from the machine) is shown in a dialog. This happens as follows:
One could use radically different approach as well where data storage is completely independent from the state machine, like a data binding library e.g. Riverpod. However, in that case you would need to have your provider known by both the machine and the ui (so to your question I think you could use bloc - I just only have experience with with Riverpod when prototyped apps with Hisma). In some cases it it could be perfectly fine with all the benefits the data binding library provides, but I partially introduced machine.data to have a simple built-in approach to transferring data from the machine layer to the UI layer where machine is independent from the data binding choices of the UI layer. Another use is what mentioned in the Wikipedia article you referenced: having data attached to the machine that is required for its operation. This other use-case is that I extensively use e.g. in the unit tests for features like minInterval, guards and onEntry, onExit actions (e.g. transition_interval_test.dart ). All in all, I think it makes sense to keep and improve the approach when data is part of the state machine itself and any comments, ideas are more than welcomed. |
Beta Was this translation helpful? Give feedback.
-
Just sharing some interesting things. |
Beta Was this translation helpful? Give feedback.
First of all thank you for your question. This is one of the areas where I did the minimum effort implementation that satisfies my initial needs for my apps but I am eager to have conversation about how to do it better.
Let's cover first what is there already. Hisma state machines have a dynamic type attribute called
data
. It can be set in the constructor and later by assigning new value to it anytime - as it is not final. Since it is dynamic you can put into this variable whatever complex data structure you want. I just realized that Hisma README.md does not describe machine.data, I will fix this...fb_auth_hisma_example is an example Flutter app that demonstrates how an existing Hisma s…