Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    David Khourshid
    @davidkpiano
    Not in the visualizer, no. Try the inspector instead
    Bharath Gedela
    @Bharath722
    Hi,
    We recently started using xstate for our statemanagement in react. So, we have a Xstate machine which contains all the context and necessary rules for transitions. And we have a nested functional, which is a typical parent component containing many child components. So is there anyway to access parent machine state (or the context to be precise) from child component without passing them as props to child component?
    David Khourshid
    @davidkpiano
    @Bharath722 What kind of info do the child components need to know from the parent?
    Bharath Gedela
    @Bharath722
    we want child component to access context from parent machine state
    @davidkpiano
    David Khourshid
    @davidkpiano
    I need specifics, or actual code. Why does it need to access context?
    Nathan Probst
    @nprbst
    QQ: I'm new to XState this week, so apologies if this is a noob question... Is there a way to spawn()a machine with a state which has been "rehydrated" like this orderMachine.resolveState(previousState)? My use case is to store the state of an OrderMachine and then load it into a PurchaseMachine at a later date. Does that make sense?
    David Khourshid
    @davidkpiano
    Not yet. Rehydration of spawned/invoked machines is an open question, still thinking through a good solution
    Brad Haydon
    @bradhaydon
    Why is it that meta information is empty when starting at an initial state? https://codesandbox.io/s/romantic-yalow-h0sk7?file=/src/index.ts
    It doesn't seem like the invoke src is firing as well
    Anthony Jackson
    @expelledboy
    If you have a nested parallel states for loading resources, where one can become final in two states, how could I determine which in the parents onDone?
    const exampleMachine = {
      states: {
        type: "parallel",
        states: {
          load: {
            doWork: {},
            success: { type: "final" },
            failed: { type: "final" },
          },
        },
        onDone: {
          // navigate to next state according to final state
        },
      },
    };
    Alexei Kozhushkov
    @joystick
    Hi, I'm spawn-ing child machine. I set it's instance on context as per docs. Child machine does some (async-ish) job and sendParent() the result. All works great.
    Could you please advise if I can suspend (to localStorage or DB) the state of a child machine from parent one using e.g. invoke?
    And then restore child machine (if necessary) on future runs?
    Thank you.
    PS: Just saw a reply to similar question a few messages earlier. No worries.
    Alexei Kozhushkov
    @joystick
    Next question is if it's possible to access to state of service?
    David Khourshid
    @davidkpiano
    NullVoxPopuli
    @NullVoxPopuli
    I know that it's been said that the next version of xstate will have sequential actions
    is there any way to try that out now?
    I need to do a bunch of assign and send stuff, but it's impossible to have correct state/context when order isn't guaranteed
    David Khourshid
    @davidkpiano
    @NullVoxPopuli want to ask in the Discord? discord.gg/xstate
    Anyway, two ways:
    In v4, you can use pure() to ensure correct action order
    And v5 already supports the correct order of actions with assign; you can NPM install the next branch from GitHub locally: https://remarkablemark.org/blog/2016/09/19/npm-install-from-github/
    Chiraag Juvekar
    @chiraag
    Is viz the correct branch for trying out a local copy of the visualizer? Is there a readme somewhere obvious that I am missing on how to set things up?
    1 reply
    vinodKumarPula
    @vinodKumarPula
    Hi @davidkpiano , I found a bug kind of thing,
    I'm using delay transition - after , and the states are persistent. So when server stops and I start again with persistent state. Only the current action will work
    Next after actions are not been assigned to actions
    5 replies
    Yarden Bar
    @ayashjorden

    Hi,
    Playing with XState actions+guards.....

    From my experiments today, an action wont get executed if its guard evaluates to false
    The docs don't refer to such use-case

    Anyone experienced the same? or different?

    "processResults": {
        "on": {
            "Result": [
                {
                    "internal": true,
                    "actions": "updateCounter",
                    "cond": {
                        "type": "someGuard"
                    }
                }
            ]
        }
    }
    Yarden Bar
    @ayashjorden
    Yarden Bar
    @ayashjorden
    My current hack would be to split this into two internal transitions:
    "processResults": {
        "on": {
            "Result": {
                "internal": true,
                "actions": [
                    "updateCounter",
                    {
                        "type": "xstate.send",
                        "event": {
                            "type": "checkCounter"
                        }
                    }
                ]
            },
            "checkCounter": [
                {
                    "target": "success",
                    "cond": {
                        "type": "someGuard <=== This transition will get selected if this condition passes (after the updateCounter took place)
                    }
                },
                {
                    "internal": true <=== This transition will get selected if the above someGuard will return false.
                }
            ]
        }
    },
    David Khourshid
    @davidkpiano
    @ayashjorden Please discuss in https://github.com/davidkpiano/xstate/discussions - and yes, the guard is for the entire transition (including actions)
    1 reply
    Alexander Praetorius
    @serapath
    @davidkpiano heya.
    i love your xstate library.
    one question: i couldn't figure out from the documentation is when i invoke a spawning of a new machine and give it a custom name, how exactly do i stop the machine?
    • maybe i missed it, but none of the objects seemed to have a .stop() method.
      another question: i have my state machines running, but sometimes the process crashes or i do not expect a specific network event any time soon (which would trigger the next transition)
      • so i'd like to either temporary shut down or in case of crash, restart a machine, but it needs to be in a specific state with a specific context.
      • i can call .withContext(...), but probably again a bignner problem - couldn't figure out how to make it start out in one or multiple states (in case its a parallel machine or something)
    2 replies
    if you can point me to specific examples or the place in the documentation where i missed that, that would be already great :-) thx
    Ivor
    @ivorpad

    Felt challenged by a tweet from @davidkpiano. https://twitter.com/DavidKPiano/status/1374752085938466816

    A circuit breaker machine https://stackblitz.com/edit/circuit-breaker — any feedback will be appreciated.

    Serhii Palash
    @serhiipalash

    In case someone is interested, I decoupled first version of Visualiser into npm-package

    https://www.npmjs.com/package/statechart-viz

    Ricardo Santos
    @rs_silvaba_twitter
    Just watched a bunch of videos related to statecharts and David's talks. The big challenge for me is switching the mindset and make a useful model using statecharts. Anyone can point material+samples for starting with modeling in statecharts?
    David Khourshid
    @davidkpiano
    @rs_silvaba_twitter https://xstate-catalogue.com
    Ribhararnus Pracutiar
    @raitucarp
    @davidkpiano Hi David, I'm sorry to bring my issue here, could you help me to look into this issue? statecharts/xstate-viz#81
    I cannot use send((context, event) => ({ }) inside actions
    Erik Mogensen
    @mogsie
    Reviving this gitter chat forum that I created just before I was persuaded to make the spectrum community. It's now linked from statecharts.dev, spectrum chat statecharts, the discussions page, etc. I feel an open (world readable) chat forum is better than a closed platform like Slack or Discord. Here's to Statecharts!
    edwlan
    @edwlan:m.edw.ai
    [m]
    Also, matrix integration is really nice.
    John Yanarella
    @johnyanarella
    Oh wow - thanks, hadn’t seen Matrix. That does look nice.
    Erik Mogensen
    @mogsie
    I've been writing a few plantuml statecharts lately, and I wonder if using that as a source syntax would be expressive enough to "compile" to an executable format, e.g. XState or SCXML? It's really good for whipping up a quick state machine, at least. Each "thing" is its own line of text.
    David Khourshid
    @davidkpiano
    @mogsie It might be hard to embed executable code in there, but the other way is easy: going from XState/SCXML to PlantUML
    Erik Mogensen
    @mogsie
    @davidkpiano I wouldnt embed executable code, but rely on conventions like "entry / foo" and "do / bar" for states, and "foo [ condition ]". The output would of course have to be coupled with actual guards, actions,services,etc.
    edwlan
    @edwlan:m.edw.ai
    [m]
    mogsie (Erik Mogensen): have you seen https://sketch.systems ? I really like their DSL and tooling for statecharts, I just wish they had some CLI tools I could embed in a CI workflow
    Erik Mogensen
    @mogsie
    Yes, but thanks for the reminder. I recall that sketch.systems didn't support the full range of staatecharts primitives, and I think I heard that they weren't heading in that direction either.
    David Khourshid
    @davidkpiano
    Yeah, work on sketch.systems has paused. Time to carry the torch
    Erik Mogensen
    @mogsie
    Indeed @davidkpiano 😁
    edwlan
    @edwlan:m.edw.ai
    [m]
    Are any of the tools behind sketch.systems open source?
    David Khourshid
    @davidkpiano
    I don't believe so
    Jared Cuffe
    @jcuffe

    Is there a standard pattern for actors who have a dependency on data managed by another actor?

    Let's say I have a CheckoutMachine and a CartMachine, and the CheckoutMachine needs to create or update a payment intent any time the items change in the cart.

    Which of these is more idiomatic?

    1. Use the data from the broadcasted CartMachine event to fetch/update the payment intent
    2. Store the data from the event on context, and then use context data to perform the fetch
    1 reply
    Ricardo Santos
    @rs_silvaba_twitter

    Hi all, I was impressed once again with the simplicity and yet powerful concepts of statecharts. I was able to really improve my code with the concepts together with the reducer hook.

    I was wondering if anyone knows articles/papers comparing statecharts to category theory it seems to me that statescharts and the actor model can be expressed as categories (or not, idk). But if you know any articles related to that please do share. Thanks.

    Denis Zhirkov
    @denyzhirkov
    Hi! Could someone explain how to manage "target" when "invoke" is an array? @davidkpiano ?
    I have an example and can show the issue - here it is
    2 replies