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

Can you match a nested state with string paths in xstate?

From the @xstate/react GitHub repo: ... for hierarchical and parallel machines, the state values will be objects, not strings. In this case, it's better to use state.matches(...) Which looks like this: if (current.matches({ loading: 'user' })) { …
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

useMachine with TypeScript throw Typescript error about mismatching types

I was following the simple example on github.com/carloslfu/use-machine to create my first example for a xstate finite machine and got stuck with the following typescript error: Argument of type '{ actions: { sideEffect: () => void; }; }' is not…
0
votes
1 answer

Transient transition that sets a value only on condition passing

Take the following code: const isWarning = () => { ... } const setWarning = () => { ... } const machine = Machine({ initial: "foo", context: { warning: null }, states: { foo: { on: { "": [ target: "bar", …
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

It it possible to define a state that transitions to itself in xstate?

Consider the following FSM: { id: 'my_machine', initial: 'foo', states: { foo: { on: { TRIGGER_BAR: 'bar' } }, bar: { on: { TRIGGER_BAR: 'bar' TRIGGER_FOO: 'foo' } } } }); Is…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

Where is the action creator message stored in Xstate?

Excerpt from the assign action docs: import { Machine, assign } from 'xstate'; // example: property assigner // ... actions: assign({ // increment the current count by the event value count: (context, event) => context.count +…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

What's the proper way to invoke actions in XState FMS?

My definition for XState FMS in the file task_statemachine.js is as follows: module.exports = { id: 'runner', initial: 'setup', states: { setup: { on: { RECEIVED: { target: 'running', actions: 'runTask', …
Yury Stanev
  • 419
  • 1
  • 5
  • 16
0
votes
1 answer

typescript - how to extend an interface at a specific location (extend a base state for library xstate)

I want to be able to extend a base interface at one or more specic locations. The idea is to be able to define a base state for the library xstate which can be extended for more specific purposes. I have interface Base { id:string; states:{ …
Han Che
  • 8,239
  • 19
  • 70
  • 116
0
votes
1 answer

can I have different values in different states in xstate

I have lots of code like this: export const getNodeShapeSize = ({ scaleToFit, compress, expanded }: { scaleToFit: boolean; compress: boolean; expanded: boolean; }): number => { if (scaleToFit) { return ShapeSizes.full; } if…
dagda1
  • 26,856
  • 59
  • 237
  • 450
0
votes
1 answer

Using send built-in action

I don't understand meaning and usage of "send" built-in action. You can see here https://codesandbox.io/embed/7467qk4rox a very simple example, with a machine with two parallel state nodes; the second one send events using send built-in action, but…
marcos82
  • 997
  • 1
  • 8
  • 11
0
votes
1 answer

Problems with using Context

I am stryggling to understand why setting Context with assign doesn't always work. I have a very simple application that you can find here https://codesandbox.io/embed/y0xk1mo9x9 I have this context: { selectedItem: 0, //Fake Value …
marcos82
  • 997
  • 1
  • 8
  • 11
0
votes
1 answer

Pass values when sending events from one machine to another in xState

I have a simple chatMachine that invokes a todoMachine. The todoMachine has an event called 'OPENED_TASK_LIST_CREATOR' which I want to invoke from chatMachine. I've managed to figure this out. export const chatMachine = Machine({ id: 'chat', …
Josh Pittman
  • 7,024
  • 7
  • 38
  • 66
1 2 3
9
10