Live data from Hacker News

Xstate: State machines and statecharts for the modern web

github.com

1–10 of 81 posts

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

#2
love how xstate makes implicit state machines explicit with a time tested (one might say Lindy) format. badly/ad hoc defined state machines are the source of so many bugs - David has been banging this particular drum the entire time i've known him (https://www.youtube.com/watch?v=HPoC-k7Rxwo&list=PLRvKvw42Rc...)

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

#3
I need to write a post on this, but I've been using this pattern to great effect:

https://gist.github.com/andymatuschak/d5f0a8730ad601bcccae97...

It doesn't require a library, it binds states and effects together, it is completely pure, and it can be implemented in most any language, preferably one with sum types and exhaustiveness checking. It works equally well with both complex, time-dependent business logic as well as code that controls UI states.

I love state machines for help in writing robust code. The act of laying them out this way forces you to consider lots of intermediate states that are ignore or forget. Plus, the logic stays away from all the gunk of the platform, state machines are trivial to test, and, once you get used to them, are easy to read.

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

#4
post #2

love how xstate makes implicit state machines explicit with a time tested (one might say Lindy) format. badly/ad hoc defined state machines are the source of so many bugs - David has been banging this particular drum the entire time i've known him ( https://www.youtube.com/watch?v=HPoC-k7Rxwo&list=PLRvKvw42Rc... )

Any sufficiently complicated model class contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of a state machine.

–a former colleague

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

#5
post #2

love how xstate makes implicit state machines explicit with a time tested (one might say Lindy) format. badly/ad hoc defined state machines are the source of so many bugs - David has been banging this particular drum the entire time i've known him ( https://www.youtube.com/watch?v=HPoC-k7Rxwo&list=PLRvKvw42Rc... )

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.

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

#6

I need to write a post on this, but I've been using this pattern to great effect: https://gist.github.com/andymatuschak/d5f0a8730ad601bcccae97... It doesn't require a library, it binds states and effects together, it is completely pure, and it can be implemented in most any language, preferably one with sum types and exhaustiveness checking. It works equally well with both complex, time-dependent business logic as we…

Seems you’re not alone. This was ripped out of Google’s Stadia platform I believe but might be wrong https://github.com/google/hierarchical-state-machine.dart

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

#7
post #5
post #2

love how xstate makes implicit state machines explicit with a time tested (one might say Lindy) format. badly/ad hoc defined state machines are the source of so many bugs - David has been banging this particular drum the entire time i've known him ( https://www.youtube.com/watch?v=HPoC-k7Rxwo&list=PLRvKvw42Rc... )

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?

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

#9
I was one half of a team that heavily leveraged XState in 2020. We used it to build a general-purpose kiosk app (in Electron) that could be updated remotely using an Xstate configuration served by a graphene-django app. One of the most technically impressive pieces of software I've ever had the pleasure to work on. (I mostly did server/backend stuff).

The entire kiosk device could be repurposed on the fly and Xstate + JSON schema form allowed for completely customizable & swappable UI.

Shame the project died.

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

#10

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?

Almost everything can be written as a state machine and arguably it’s very useful to do so, for example let’s take a note taking app, you can probably list a set of transitions that can happen to change the state of the app. Keeping the state changes separate from the UI is a good thing. In a way redux is a state machine too. Try it out on a project and see if it works for you!
Post reply on HN