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
0
votes
1 answer

JavaScript: xState: Connection to database implementation

I'm new to xState state machine library and am trying to implement a database connection and get data states using a third-party library. This library has a connect, disconnect functionality. It publishes 3 events, loginSuccess,…
SoftwareDveloper
  • 559
  • 1
  • 5
  • 18
0
votes
1 answer

Can I access the state of a React Query mutation across files?

In one file, I have export const useAlertMachine = () => { const updateAlertsMutation = useUpdateAlerts(); return { updateAlertsMutation }; }; updateAlertsMutation has states isLoading, isSuccess, isIdle, and isError. I want to be able to…
Collin Sinclair
  • 453
  • 1
  • 3
  • 12
0
votes
1 answer

XState display context values in another file

I am learning XState with React Native. I have a form and I want to display on another screen the value which I took from the form. I pass the value to the machine but when I want to try to display it on another screen, the context is empty. How can…
0
votes
0 answers

Method parameter casted to my type but its property is not recognized

I am using XState and I need to pass a parameter via an Event. export type InitializationEvent = | { type: 'FETCHED', name: string } | { type: 'ERROR', name: string } | { type: 'RESTART', name: string } This is a method where I want to use…
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
0
votes
1 answer

Method referenced in XState machine is not callable within class but works when declared as global

Why cannot I reference a method declared within the same class as XState service? If I move the method outside of the class, it works fine. export class LoaderMachine { service = interpret(createMachine( …
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
0
votes
1 answer

Xstate fsm typescript incompatibility for TState

I have started to play with xstate/fsm and I have an issue with declaring a TState type. import {createMachine, EventObject, StateMachine} from '@xstate/fsm'; import {Typestate} from "@xstate/fsm/lib/types"; export interface InitContext { retries:…
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
0
votes
0 answers

Electron console.log emitted from two different places/files?

I've got an electron app with vite/xstate/react. In development I'm seeing just a single xstate.init event emitted when starting up the app. But in production builds, I see two xstate.init events (there should only be one, triggered by xstate itself…
timothym
  • 2,853
  • 5
  • 19
  • 26
0
votes
1 answer

Proper type for services in fetchMachine (xstate, typescript)

I started playing with xstate and decided to start with making a fetch machine that will be responsible for every request I make to the server. I created a simple state machine: import { createMachine, assign } from "xstate"; interface FetchContext…
0
votes
0 answers

Does context for conditional rendering belong in a data machine?

I'm finally integrating xstate into my work project because I love it and I'm excited to show off what well-structured states can do for performance and reasoning, but I'm struggling with a bit of modeling. I have a weatherMachine that gets the…
sunny-mittal
  • 499
  • 5
  • 12
0
votes
1 answer

How to react to a substate change in xState

I've inherited a react project using xState which is pretty unknown to me. In this machine there is a "saving" state having a few substates. Something like this: states : { saving: { id: 'saving', initial: 'saving', …
Henrik Clausen
  • 679
  • 6
  • 16
0
votes
1 answer

How to run action first, then conditionally target in xstate

I am using xState app machines and I am finding myself needing to do things in sequence. Below when I fir NAV_OK, I want it to run the action 'run-search' first, then after it runs, I want it to focus automatically on the correct element based on…
lache
  • 608
  • 2
  • 12
  • 29
0
votes
1 answer

Issue upgrading XState's Reddit sample from Vue 2 to Vue 3

After reading the XState documentation I followed the Reddit sample found at the official guide, here: https://xstate.js.org/docs/tutorials/reddit.html I was trying to upgrade to Vue 3 the sample implementation by Chris Hannaby but I couldn't. When…
gsaielli
  • 23
  • 6
0
votes
2 answers

Invoke a service from a "serverless" fsm (Xstate)

I'm using xsate on a Node.JS backend. Here is the current flow : State is rehydrated (Initialized or fetched from DB) Event is sent to the FSM State is serialized to DB Here is some pseudo code const state = db.fetch(flowId) ??…
bokzor
  • 413
  • 7
  • 19
0
votes
1 answer

XState TypeScript - useInterprete Service

I am building a login machine with TypeScript and xState combined with React UI. My machine is: import { LoginResponse } from 'async/authentication/responseModel'; import Data from 'data'; import { AUTH_TOKEN } from…
Priyank Thakkar
  • 4,752
  • 19
  • 57
  • 93
0
votes
1 answer

Statecharts for Redux

Current State Management Stack: React, RTK/Redux, and Redux-Saga Here's the high level issue. We have a complex flow and we don't have QA Engineering resources to be able to write the integration tests needed for this. This leads to the following…
Bobby Gagnon
  • 80
  • 2
  • 11