-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we send data to another State when activating it? #13
Comments
This library doesn't enforce a specific way to model or pass data. The most strait-forward way would be if you stored the object in a variable that both handlers have access to. A more generic way would be to use custom state objects, and use a transition handler to propagate the value from the previous state to the next one. |
Can you please give me an example of the transition handler approach? |
class Data {
String? input;
String? output;
}
void main() {
final machine = Machine<Data>();
machine.onBeforeTransition.forEach((event) =>
event.target?.identifier.input = event.source?.identifier.output);
final stateA = machine.newState(Data());
final stateB = machine.newState(Data());
stateA.enter();
stateA.identifier.output = 'Hello';
stateB.enter();
print(stateB.identifier.input); // Prints 'Hello'
} |
What do you think about
Internally, the state can hold the data as |
That sounds like a useful idea, if the typing doesn't get too messy. I have to think about this a bit more. |
In either case the API would not be backward compatible (adding a generic type is breaking this). Any other ideas? |
I agree that this would be not backwards compatible. Adding |
Consider two states
StateA
andStateB
.StateA
has a transition inside which a methodmA1
is executed and it produces some objecto1
. After,mA1
is executed, we set thecurrent
state toStateB
. On enteringStateB
, we need to call another methodmA2
with the previously produced objecto1
.How do I achieve this? I think this can be achieved using Streams, but is that the best solution?
The text was updated successfully, but these errors were encountered: