Skip to content

Instantly share code, notes, and snippets.

@neilmanuell
Last active September 27, 2015 13:37
Show Gist options
  • Save neilmanuell/1277913 to your computer and use it in GitHub Desktop.
Save neilmanuell/1277913 to your computer and use it in GitHub Desktop.
AS3 API for TryHarderStateMachine
fsm
.configureState( StateNames.HAPPINESS )
.withEntryGuards( OnlyIfHappy, OnlyIfSmiling )
.withExitiGuards( OnlyIfAnxious )
.withTargets( StateNames.SADNESS, StateNames.ECSTACY );
fsm
.configure( ProcessNames.GET_HAPPY )
.ifCurrentState( StateNames.FRUSTRATED )
.transition( StateNames.ANNOYED, StateNames.EXPECTATION )
.ifCurrentState( StateNames.EXPECTATION )
.transition( StateNames.EPIPHANY, StateNames.HAPPINESS )
.elseThrowError();
fsm.mapProcess( ProcessNames.GET_HAPPY )
.to( HappyEvent.GET_HAPPY )
.unlock( StateNames.EXPECTATION ).after( HappyEventTrigger );
fsm
.during( StateNames.HAPPINESS)
.cancellation
.always.execute( DoThis, DoThat ).onApproval( OnlyIfThat )
.and.always.execute( DoTheOther )
fsm
.during( StateNames.HAPPINESS)
.tearDown
.always.execute( DoThisCmd ).onApproval( OnlyIfThis ) // executed only if all guards approve
.and.always.execute( DoThatCmd ).onApproval( OnlyIfThat ) // executed only if all guards approve
.and.always.execute( DoTheOther ) //always executed;
fsm
.during( StateNames.HAPPINESS )
.cancellation
.either.execute( DoThis, DoThat ).onApproval( OnlyIfThat ) // executed only if all guards approve
.or.execute( DoTheOther ) // executed only if previous commands are not executed
.and.always.execute( SomethingElse) // always executed
@derekdon
Copy link

derekdon commented Dec 9, 2011

yeah no worries mate, I know the feeling...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment