Questions tagged [xstate]

xstate is Javascript library for creating finite state machines and statecharts.

xstate is library for creating finite state machines and statecharts in JavaScript. Code and links to documentation found at https://github.com/davidkpiano/xstate

146 questions
1
vote
1 answer

Sending data from parent machine to child machine using actors

I'm trying to understand Actors to be able to pass data from a sibling component to another. I have these machines: parent and child. parentMachine sends a GET event to childMachine in the success transition. Once childMachine receives an…
Ivor
  • 590
  • 6
  • 21
1
vote
1 answer

Difficulty resolving errors with imports in Javascript

I am new to JavaScript and vscode and getting it set up has been more difficult than any other language I have used at work. When I run the code (in Test.js): var msg = 'here'; console.log(msg); import { Machine, interpret } from…
Chilly
  • 25
  • 5
1
vote
2 answers

Is there a way to have guarded transitions within Hierarchical State Nodes in xState

As title implies, I have a guarded transitions that I wanted to be in a Hierarchical State Node, however it seems that xState can not read property of guards and returns a "TypeError: Cannot read property 'propertyName' of undefined" error" Is…
1
vote
1 answer

mocking an invoked promise in xstate

I am trying to test that a promise is invoked when a state transition happens. I followed the approach outlined in the official xState tutorial but I get the following error Timeout - Async callback was not invoked within the 5000ms timeout…
Josh Pittman
  • 7,024
  • 7
  • 38
  • 66
1
vote
1 answer

XState react - share machine instance across multiple components

I have two machines: AuthenticationMachine and AddressMachine. AuthenticationMachine is used by Login component while AddressMachine is used by Address component. But I need token from AuthenticationMachine in Address component to be used with the…
Joshua
  • 589
  • 1
  • 5
  • 19
1
vote
2 answers

What happens if you send an event that doesn't exist in React Xstate?

Take this finite-state machine: { initial: "foo", states: { foo: { on: { BAR: "bar" } }, bar: { on: { FOO: "foo" } } } } And in my component, I do this: import { useMachine } from "@xstate/react"; export default…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
1
vote
1 answer

How to get all possible transitions from a state in xstate

Given an xState fsm like the counter or search example. How is it possible to enumerate the possible transitions? I tried const current = service.state const stateNode = service.machine const isActive = !stateNode.parent ||…
philk
  • 2,009
  • 1
  • 23
  • 36
1
vote
1 answer

Spawning children machines in xstate

I am currently working on an application using xstate, I have a parent machine that spawns into two different children's machines, the children machines make a fetch to different API endpoint and they all send back to the parent a resolve or reject…
dealwap
  • 621
  • 2
  • 14
  • 33
1
vote
1 answer

checking the cond statement in xstate machine defenition

I have the following code, the condition in start state is giving me trouble. const machine = require('xstate'); let test = true; // Stateless machine definition // machine.transition(...) is a pure function used by the interpreter. const…
Yury Stanev
  • 419
  • 1
  • 5
  • 16
1
vote
2 answers

How to get the initial state of a hierarchical xstate machine?

Assuming we have the following simplified hierarchical xstate machine... const HFSM = Machine({ initial: 'init', states: { init: { initial: 'leaf' } } }); ...what is the best way to get its initial state? Note that HFSM.initial…
sookie
  • 2,437
  • 3
  • 29
  • 48
0
votes
0 answers

XState using the service outside React component

I need to be able to access my state machine outside of a React component in a form session that is handled by a 3rd party. Here is the configuration I have and since I'm new to xstate I wanted to see if this was a proper solution: //…
Jamie
  • 1,909
  • 3
  • 22
  • 47
0
votes
2 answers

XState action is not called for `machine.transition()`

I have a simple machine: import { createMachine } from 'xstate' export const machine = createMachine( { predictableActionArguments: true, schema: { context: {} as { elapsed: number }, events: {} as { type: 'AT_SAFE_ZONE' } | {…
Rodrigo
  • 135
  • 4
  • 45
  • 107
0
votes
0 answers

XState - modeling parent/child state machines with connected states

XState newbie here. Apologies if this is a very basic question. I'm attempting to model a workflow containing multiple steps each with its own set of states, and I'd like the parent workflow to have states that mirror the child records. Something…
kid_drew
  • 3,857
  • 6
  • 28
  • 38
0
votes
0 answers

With xstate, how can I access the machine's current state when predictableActionArguments=true

My xstate error machine has an "error" state which logs as much debug information as possible on entry: const myMachine = createMachine({ states: { …, error: { entry: (context, event, meta) => { console.error( …
David Wolever
  • 148,955
  • 89
  • 346
  • 502
0
votes
1 answer

test xstate final state

I'm trying to test the login of my state machine written with Xstate. I'm wondering how I can test the login and the state-change, let me do an example: my state machine is doing these 3 steps: init (with guard) -> step 1 (service call) ->…
stix
  • 21
  • 3