I have error integrating xstate in svelte component

140 views Asked by At

I am working on a svelte project with xstate in my app.svelte I have this code =

  <script>
  import { Machine } from 'xstate'
  import { useMachine } from 'xstate-svelte';
  

  enum STATE {
        LOADING = 'LOADING',
        LOGIN   = 'LOGIN',
        PLATFORM= 'PLATFORM',
    }
    enum EVENT {
        NEEDING_TO_LOG  = 'NEEDING_TO_LOG',
        LOGGINGIN       = 'LOGGINGIN',
        LOGGINGOUT      = 'LOGGINGOUT',
    }
    const machine = Machine({
        id      : 'pages',
        initial : STATE.LOADING,
        states  : {
            [STATE.LOADING] : {
                on : {
                    [EVENT.LOGGINGIN] : STATE.PLATFORM,
                    [EVENT.NEEDING_TO_LOG] : STATE.LOGIN,
                }
            },
            [STATE.LOGIN] : {
                on : {
                    [EVENT.LOGGINGIN] : STATE.PLATFORM,
                }
            },
            [STATE.PLATFORM] : {
                on : {
                    [EVENT.LOGGINGOUT] : STATE.LOGIN,
                }
            },
        },
    });
    const { state, send } = useMachine(machine);
    function sendFsm(event: EVENT): void {
        send(event);
    }




</script>

<main>
    <h1>H1</h1>
    
    <h1>Hello {JSON.stringify(state)}!</h1>
    <button on:click={ () => sendFsm(EVENT.LOGGINGIN)}>Login</button>
    <button on:click={ () => sendFsm(EVENT.LOGGINGOUT)}>Logout</button>
    
</main>

when doing a npm run dev, I have this error

node_modules/xstate/es/scheduler.js (27:11) 25: } 26: 27: this.process(callback); ^ 28: } Error: Unexpected token at error (/home/matias93/Escritorio/proyecto-2.0/plataforma-web/node_modules/rollup/dist/shared/rollup.js:5252:30) at Module.error (/home/matias93/Escritorio/proyecto-2.0/plataforma-web/node_modules/rollup/dist/shared/rollup.js:9820:16)

0

There are 0 answers