Guards

Conditional actions and transitions

Guard

is a                  checking if action or transition is allowed to happen 

function

Guards can be passed

in special           property

cond

{
  on: {
    EVENT: {
      actions: "someAction",
      target: "someState",
      cond: (context, event) => {
        // logic that determines 
        // whether to return true or false
      }
    }
  }
}

Multiple guards

guards deciding transitions

{
  on: {
    EVENT: [
      {
        target: "foo",
        cond: "someGuard"
      },
      {
        target: "bar",
        cond: "someAnotherGuard"
      }
    ]
  }
}

coding time!

5. Guards

By Kuba Skoneczny

5. Guards

  • 167