Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    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
    geekox86
    @geekox86
    image.png
    image.png
    image.png
    ckp95
    @ckp95
    hey, ive been looking into statecharts having not heard of them before. im trying to understand how they work. how would you represent a UI that needs to have a dynamic number of options? for example a simple file manager ... the user would be able to use arrow keys to move up and down in the list, and then press other keys to do things to the selection like open or delete or rename or something. since the number of files in the folder is unknown until runtime, how do you represent them as states?
    Erik Mogensen
    @mogsie
    @ckp95 you want to avoid making a state for a variable number of things. Split it up in ways that make sense, paying attention to how the behaviour changes. For example, if a list is empty or has 5 items, it behaves differently. If there is one item, it behaves differently than if there are two, but there might be no behavioural differences between having 2 items or 3 items or more. In that case you might consider states like:
    • empty
    • single
    • multiple
      to capture the three different ways the list can behave.
    Erik Mogensen
    @mogsie
    You might also model e.g. the current selection, as being nothing selected, and if something is selected, you might want to have (sub) states that represent different behaviours depending on what is selected. e.g. if it is editable, or readable, or is a directory, and so on. Substates and parallel states may help here.
    Erik Mogensen
    @mogsie
    The current selection would probably also behave differently depending on if it's at the beginning or end of the list; at the top, you might not be able to go "up" and at the bottom you wouldn't be able to go "down". These are examples of behaviours that can be modeled as states, without trying to model each element as separate states.
    Now this doesn't stop you from instantiating a sub-machine of some sort, if the items you're working on have complex behaviours themselves; but IMHO those should be kept separate, and only communicate using typical component communications techniques like events and attributes, much like any other component.
    Uriel Avalos
    @robotandkid_gitlab

    hey guys. Been struggling to model a kid's video game with state machines. So... the screen is populated with dots. The user is asked to perform various commands that changes the game state. (Ex: Shake the screen, press a green dot, etc).

    For simplicity, there's the (1) "Press a X color dot" command, (2) the "Rotate the screen" command, and (3) the "Shake the screen" command.
    The game can go to (1) if a dot of the given color exists and if the screen hasn't been rotated. When the user presses the given colored dot, it will add a random colored dot. (2) occurs as long as the screen isn't already rotated. A rotation undoes a shake. (3) Shaking the screen undoes a rotation. We care about this because the command shown to the user is one of "Shake the screen" or "Shake the screen again".

    So part of the problem is that as you can see the commands are tightly coupled. If I add another one, the chance of adding a bug is fairly high. So I'm struggling to model the game state correctly with state machines.

    1 reply
    David Khourshid
    @davidkpiano
    I suggest making a state transition table outlining what can and can't happen in each state. You have 3 states: "pressing dot", "screen rotated" "screen shook"
    1 reply
    Michael Egger
    @megger-ccore_gitlab
    Hello,
    assume a statemachine, that switches to a state automatically after a delay. e.g. `<onentry> <send event="autoLock" delay="5s" id="idleTimer"/> </onentry>
    It is loaded in a program from a scxml file.
    How would you handle customizing the delay? So, if a user wants to increase the delay to 10s, would you still use the statemachine delay facility? This would mean, that the statemachine at runtime is different from the statechart. Or would you remove the delay from the statechart (scxml) and just call a timer that has a configurable delaytime?
    I am not sure, if it is even possible to change the delay after the statemachine was loaded from the scxml file. That is, using QScxmlStateMachine.
    2 replies
    garyzhuge
    @garyzhuge
    Hi everyone, I'm an iOS dev interested in using state Charts to set up automated testing of a reactive plugin. Can anyone recommend a good state Chart libary for swift or should I roll my own?