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
183
votes
3 answers

What is an actual difference between redux and a state machine (e.g. xstate)?

I am working on investigation of one front-end application of medium complexity. At this moment it is written in pure javascript, it has a lot of different event-based messages connecting few main parts of this application. We decided that we need…
Artem Arkhipov
  • 7,025
  • 5
  • 30
  • 52
10
votes
2 answers

What is the difference between an actor and invoking services in xstate?

I am just a little bit confused on what is the difference between actors and invoking services in xstate since they look just the same to me.
8
votes
0 answers

Cleaning and stopping spawned actors from inside a service in Xstate

I have extensively read the docs, however, there are still some parts that are not entirely clear, and most have to do with actors/services I am a little fuzzy on the details of spawned actors' lifecycles. Will calling .stop() on a service with…
Dimitris Karagiannis
  • 8,942
  • 8
  • 38
  • 63
5
votes
0 answers

Jest snapshot tests pass locally but fail on Jenkins

I have a series of snapshot tests that pass locally. But on Jenkins, my component seems to be rendering a different snapshot. My tests are: import { render } from 'enzyme'; import React from 'react'; import Wizard from…
Athanasia
  • 51
  • 3
5
votes
3 answers

How to persist state in Xstate state machines in react?

I have a working cart state machine to add items in cart I'm using reactjs. On refreshing page, context is not persisted.I`m new to state machines and would like to persist state in my app.Below is my cartMachine .Please help.Thank you. export const…
Rickhomes
  • 135
  • 1
  • 8
5
votes
1 answer

how in XState machine to do action send('EVENT_NAME', {to:'something from context'})?

I need send event to another spawned state machine that its ID I have as a string in a variable in the context. (it is not parent state machine and not child) Like context.sendTo = 'B_id' how to do send() with parameter from context? and how to…
Boris Daich
  • 2,431
  • 3
  • 23
  • 27
5
votes
1 answer

XState: Wait for response of invoked function

I am planning to use XState for managing states in the backend of my application. When an api is called, a function will be called on successful state change. The result of the function call has to be returned as response of the api. // Returns a…
suku
  • 10,507
  • 16
  • 75
  • 120
4
votes
2 answers

xstate: how can I initialize the state to a specific node?

I have a multi step form that basically has these basic steps: select services -> contact -> billing. I display a progress bar and emit events when the user changes the step they're on, and this is my current basic pattern with xstate: const…
corvid
  • 10,733
  • 11
  • 61
  • 130
4
votes
3 answers

xstate - how to properly handle transitions errors?

I'm completely new to Xstate and I'm struggling to find help inside the official documentation. The problem is pretty easy, I'd like to know if an event is triggered when is not suppose to. I have a basic workflow that is very strict in terms of…
Dario
  • 755
  • 1
  • 7
  • 19
4
votes
1 answer

XState.js How to send context to a machine?

I am new to XState.js. I want to use a simple ID in my context. How do I update the context using machine.send()? const fetchMachine = Machine( { id: 'test', initial: 'init', context: { id:…
abnormi
  • 628
  • 1
  • 7
  • 15
4
votes
2 answers

Send event to array of child services in XState

I have a scenario where I have one parent machine and several child machines that can be spawned from the parent machine. The current setup looks like this: const parentMachine = Machine({ context: { children: [] //can contain any number of…
Drew Jex
  • 845
  • 2
  • 13
  • 24
4
votes
1 answer

How to reuse state transitions in xstate?

Take the following finite-state machine: const machine = Machine({ initial: "foo", states: { foo: { on: { BAZ: "baz", QUX: "qux", }, }, bar: { on: { BAZ: "baz", QUX: "qux", }, …
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
3
votes
2 answers

Using XState, how can I access name of current state in an action?

I'm playing around learning XState and wanted to include an action in a machine that would just log the current state to console. Defining a simple example machine like so, how would I go about this? Also note the questions in the comments in the…
Sigmatic
  • 103
  • 1
  • 6
3
votes
1 answer

Using xstate, is it possible to configure an event that is applicable under all states and is handled in the same way across all states and substates?

I am new to xstate, and I'm trying to use it in an application where a user can request different things in an application, based on parent state and/or sub-state. However, there are some requests that the user should be able to make, no matter…
3
votes
1 answer

XState: chaining multiple promises without intermediary states

I've read the Invoking Multiple Services section, which says that one could invoke multiple promises, but in my own tests they look to be invoked without waiting for the previous to finish // ... invoke: [ { id: 'service1', src: 'someService' }, …
Coding Edgar
  • 1,285
  • 1
  • 8
  • 22
1
2 3
9 10