ChrisShank / xstate-vue2

Vue 2 composables for XState.
MIT License
19 stars 5 forks source link

always doesn't work #8

Closed idmytro closed 1 year ago

idmytro commented 1 year ago

This simple machine doesn't work with xstate-vue2, but works with @xstate/vue

const simpleMachine = createMachine({
  id: 'simple',
  initial: 'idle',
  states: {
    idle: {
      always: [
        {actions: 'log', target: 'active'}
      ],
    },
    active: {}
  }
},
{
  actions: {
    log: () => console.log('log')
  }
})
ChrisShank commented 1 year ago

Peculiar, I think I can reproduce this https://stackblitz.com/edit/vite-9wsjog?file=main.js

Cannot set properties of undefined (setting 'value')

Seems like listener is called before the state variable is initialized. Should be easy to fix :)

ChrisShank commented 1 year ago

Okay so this was a regression caused by the last bug fix. @xstate/vue doesn't have this bug because that other bug hasn't been patched. I'll try to fix this regression tomorrow, thanks for reporting!

daniel-n-dream commented 1 year ago

I also get the error Cannot set properties of undefined (setting 'value') with a Machine that uses Always transitions a lot, is there any possible workaround or update on this @ChrisShank ?

ChrisShank commented 1 year ago

Fixed in v0.3.2

See the reproducer with the latest version https://stackblitz.com/edit/vite-vqm8hy?file=package.json