Live data from Hacker News

Xstate: State machines and statecharts for the modern web

github.com

21–30 of 81 posts

Re: Xstate: State machines and statecharts for the modern web

#21
post #18

The readme gives the example of a traffic light to demo a state machine usecase. Fair enough, but what's a rudimentary usecase for 'the modern web'? What everyday UI thing is better done with this than other methods? Why is it better?

The ubiquitous waiting/loading/error(msg)/success(data) Lots of frameworks and state management libraries already lean towards helpful design, in languages with async and ADTs as first-class citizens you've got a real leg up, but at the end of the day it comes down to preventing impossible states. You can't have an error message when in the success state, you can't have success data while loading or waiting. By preve…

I think a switch or an if/else expresses this really clearly though and also prevents impossible states.

Re: Xstate: State machines and statecharts for the modern web

#22
post #5

Earlier quoted context omitted.

I wonder if we could build better implicit state machines if we could more easily visualize our imperative code by annotating it with visualization hints and parsing the AST. Also easier to debug/step-through this way.

Then why not just make it explicit?

Having really good tracing/observability on an explicit state machine like Xstate would be such a great superpower.

Re: Xstate: State machines and statecharts for the modern web

#25

Earlier quoted context omitted.

Sounds awesome, given it died could you publish the source? Would be great to see how something like this is structured.

Unfortunately no. It was proprietary. (we pushed to open source the guts, but to no avail) Both of us reminisce about it though. We literally retooled the fleet of devices in a weekend to adapt to COVID and it worked. We interfaced with tons of hardware and even ran a customized debian image, all powered by RPis. Truly a nerd's dream project.

We're currently building something that sounds superficially similar, would you be interested in having a chat?

Re: Xstate: State machines and statecharts for the modern web

#26
post #25

Earlier quoted context omitted.

Unfortunately no. It was proprietary. (we pushed to open source the guts, but to no avail) Both of us reminisce about it though. We literally retooled the fleet of devices in a weekend to adapt to COVID and it worked. We interfaced with tons of hardware and even ran a customized debian image, all powered by RPis. Truly a nerd's dream project.

We're currently building something that sounds superficially similar, would you be interested in having a chat?

Sure. Check bio. Email in blog's about page.

Re: Xstate: State machines and statecharts for the modern web

#27

The readme gives the example of a traffic light to demo a state machine usecase. Fair enough, but what's a rudimentary usecase for 'the modern web'? What everyday UI thing is better done with this than other methods? Why is it better?

The usual "the examples are so trivial to implement safely in other ways that I don't see the benefits".

Re: Xstate: State machines and statecharts for the modern web

#28

I've seen XState more and more, recently, what are the pros and cons versus other state management solutions? Anything that XState fails at particularly that potential users should be aware of?

Verbosity, complexity. It's probably overkill for 99.9% of the things you imagine.

Learning curve is more similar to rx-js or fp-ts than a state manager.

Re: Xstate: State machines and statecharts for the modern web

#29

I've seen XState more and more, recently, what are the pros and cons versus other state management solutions? Anything that XState fails at particularly that potential users should be aware of?

The story for composition and reusability of multiple state machines is not good and it's not compatible with existing solutions for certain things (react query for example.) Supposedly this will all be fixed to some extent in v5 but that hasn't launched yet.

Re: Xstate: State machines and statecharts for the modern web

#30
post #18

The readme gives the example of a traffic light to demo a state machine usecase. Fair enough, but what's a rudimentary usecase for 'the modern web'? What everyday UI thing is better done with this than other methods? Why is it better?

The ubiquitous waiting/loading/error(msg)/success(data) Lots of frameworks and state management libraries already lean towards helpful design, in languages with async and ADTs as first-class citizens you've got a real leg up, but at the end of the day it comes down to preventing impossible states. You can't have an error message when in the success state, you can't have success data while loading or waiting. By preve…

I think this is solved more generally with a discriminated union in typescript.

A state machine is the wrong solution unless you also need to restrict transitions themselves in my opinion

Post reply on HN