TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Do you use State Machines for UI dev?

27 pointsby orixilusover 7 years ago
I&#x27;ve been searching for new, &quot;better&quot; workflows for UI development for enterprise applications (web based, SaaS) and been stumbling upon state-machines more than once.<p>Smashing Magazine has a nice writeup [0] today and there are some interesting libs ([1], [2], [3], [4]) already in JS.<p>My question is, does it work for you? Is this a better solution?<p>[0] https:&#x2F;&#x2F;www.smashingmagazine.com&#x2F;2018&#x2F;01&#x2F;rise-state-machines&#x2F; [1] https:&#x2F;&#x2F;github.com&#x2F;krasimir&#x2F;stent [2] https:&#x2F;&#x2F;github.com&#x2F;intersel&#x2F;iFSM [3] https:&#x2F;&#x2F;github.com&#x2F;burrows&#x2F;statechart.js [4] https:&#x2F;&#x2F;github.com&#x2F;jakesgordon&#x2F;javascript-state-machine&#x2F;

9 comments

indescions_2018over 7 years ago
Borrowing the concept of scene graphs from gamedev is one technique I like to use.<p><a href="https:&#x2F;&#x2F;webglfundamentals.org&#x2F;webgl&#x2F;lessons&#x2F;webgl-scene-graph.html" rel="nofollow">https:&#x2F;&#x2F;webglfundamentals.org&#x2F;webgl&#x2F;lessons&#x2F;webgl-scene-grap...</a><p>Another data driven architecture is to make extensive use of the Dataset property. Every element has a unique key associated with it. And all keys map to state objects in a data store. It then becomes easier to iterate and extract the relevant queries and stats.<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Learn&#x2F;HTML&#x2F;Howto&#x2F;Use_data_attributes" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Learn&#x2F;HTML&#x2F;Howto&#x2F;Us...</a><p>There&#x27;s no perfect one size fits all solution. But data oriented design is a great tool for starting to break down your app. Best of luck!
ecesenaover 7 years ago
I know it&#x27;s not precisely what you&#x27;re asking, but in the python world there&#x27;s this new and pretty interesting library, Automat [1].<p>I believe it&#x27;s used in Twisted, or at least that use case strongly influenced the lib design.<p>I also found this talk about Automat [2] very interesting (though, to be honest, I don&#x27;t fully like the example described.)<p>Anyway, this is not js nor ui, but if you decide to go for building your own js lib, I&#x27;d definitely look into porting automat.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;glyph&#x2F;automat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;glyph&#x2F;automat</a><p>[2] <a href="https:&#x2F;&#x2F;youtu.be&#x2F;MtHscXjWbVs" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;MtHscXjWbVs</a>
tethetaover 7 years ago
I would check out <a href="https:&#x2F;&#x2F;github.com&#x2F;davidkpiano&#x2F;xstate" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;davidkpiano&#x2F;xstate</a> It&#x27;s the one I&#x27;ve been most tempted to try. Ryan Florence has a good video of it somewhere.<p>I haven&#x27;t used explicit state machines in the past but there are a few apps that would have greatly benefited. I ended up using Redux reducers as a sort of pseudo state machine.
itamarstover 7 years ago
Everyone building a UI uses state machines. It&#x27;s just that some of them are implicit, badly structured, and have broken edge cases.
评论 #16073325 未加载
bigmanwalterover 7 years ago
I don&#x27;t use a state machine library, but I do put all my state in a single object, and define my state transitions as functions which operate on the object. The state is rendered into html using mithril.<p>I&#x27;m not sure what another library would add to this.
merrinkurianover 7 years ago
I have seen state machine explicitly coded for handling menu items. Based on the current state, there are a bunch of menu items that need to be enabled&#x2F;disabled. Prior to using state machine they were hand coding all these enable&#x2F;disable logic. Regression testing was a nightmare. Once they moved to the state machine adding new menu items and testing became super easy. That is menu changes became config changes and not code changes.
ahartman00over 7 years ago
Yes, I&#x27;ve used jakesgordon&#x27;s. I really recommend it, both the use of state machines and the library.<p>Using a state machine really helped making it obvious what needed to be cleaned up. If you have something with many states, which may even transition back and forth, it really organizes everything, making bugs less likely. It also prevents you from going to invalid states from the current state.
fvargasover 7 years ago
This video on the use of Finite State Machines in the context of React&#x2F;JS may be of interest:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VU1NKX6Qkxc" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VU1NKX6Qkxc</a>
orixilusover 7 years ago
thanks everyone for your input