Xstate: Question : actions are executed even with no target

Created on 16 Oct 2018  路  3Comments  路  Source: davidkpiano/xstate

Bug or feature request?

Question

Description:

in xstate, actions are executed even if there is no "reel" transition.

In the exemple below, when I send transition run, new state has logRun as action.

javascript const machine = Machine({ initial: 'a', states: { a: { on: { run: { actions: ['logRun'] } } } } })

I wonder whether it is a normal behavior, a good practice.

Link to reproduction or proof-of-concept:

Find code here

invalid question

All 3 comments

This kind of transition is a "targetless transition", related to #134. And mentioned in the SCXML spec.

Right, and this in particular is an "external" transition - where the state enters and exits itself. This will also occur with an "internal" transition (internal: true) because the action is defined on the transition itself.

It's actually quite useful! Imagine a counter machine (v4):

{
  on: {
    // Update extended state but don't change finite state
    INCREMENT: { actions: assign({ count: ctx => ctx.count + 1 }) }
  }
}

thanks for reply.
Totally agree, it's quite useful, but I was not sure it was expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mreinstein picture mreinstein  路  3Comments

carloslfu picture carloslfu  路  3Comments

dakom picture dakom  路  3Comments

3plusalpha picture 3plusalpha  路  3Comments

drmikecrowe picture drmikecrowe  路  3Comments