-
Notifications
You must be signed in to change notification settings - Fork 147
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 to define input common to all states? #141
Comments
1/ I don't think there is a direct way to do it. On my side, I did it like this in the state machine initializer function:
2/ I think so. You 'input_here' will be called if your child state machine current state has no such input defined. Documentation mentions:
|
Oh, that was clever! Thank you for the tip, will consider that! |
@bedeho Apologies for the long delay in replying :) (see #146). There actually is a shortcut way to implement a common handler for all states, though I highly recommend using it with caution, since I believe it's always better to explicitly declare what inputs each state handles. If you implement a method at the top of the FSM and then call const list = new machina.BehavioralFsm({
namespace: "priorityTest",
initialState: "ready",
states: {
ready: {
next: "todo"
},
todo: {
next: "doing"
},
doing: {
next: "done"
},
done: {
next() {
console.log( "I already made the donuts...." );
}
}
},
next( client ) {
this.handle(client, "next" );
},
altNext( client ) {
this.handle( client, "next" );
}
} ); In the above example, any of these three ways effectively feed a let client = {};
list.next(client);
list.altNext(client);
list.handle(client, "next"); This also holds true for a top level catch-all |
Is this
input_here
allowed, and when will it be triggered?The text was updated successfully, but these errors were encountered: