123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051open!CoreopenBonsai_webmoduleAction=structtypet=|Activate|Run_if_active[@@derivingsexp_of]endmoduleModel=structtypet={activated:bool}[@@derivingsexp,equal,compare]endletcomponenteffect=letopenBonsai.Let_syntaxinlet%sub_,run_action=Bonsai.state_machine1~equal:[%equal:Model.t]~sexp_of_action:[%sexp_of:Action.t]~default_model:{activated=false}~apply_action:(funcontextinputmodelaction->matchinputwith|Activeinput->(matchactionwith|Activate->{activated=true}|Run_if_active->ifmodel.activatedthen(Bonsai.Apply_action_context.schedule_eventcontextinput;{activated=false})elsemodel)|Inactive->eprint_s[%message[%here]"An action sent to a [state_machine1] has been dropped because its input \
was not present. This happens when the [state_machine1] is inactive \
when it receives a message."(action:Action.t)];model)effectinletrun_if_active=let%maprun_action=run_actioninrun_actionRun_if_activeinlet%sub()=Bonsai.Edge.after_displayrun_if_activeinlet%arrrun_action=run_actioninrun_actionActivate;;