Now that status is stored in one spot, your UI can’t get in an illogical state. For example, with separate isLoading and isErrored state, they could both feasibly be true at the same time. That’s a bug. A single status var assures an illogical status cannot occur.
-
-
Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
I created XState, but I completely agree. Also: don't put logic in event handlers, and don't base logic on only the event that happened. Determine the behavior for each "finite state". You can encapsulate each state's behavior in a function, for example.
-
Dang you’re fast David! I’m transitioning a 1000 line React component with 14 useState calls to use xState today. I am eager to share my thoughts when I’m done.
- Još 3 druga odgovora
Novi razgovor -
-
-
That enforces that the state is always one of your enumerated values, but it doesn't enforce the allowed transitions between those states. Much better than five booleans though.
-
Yep agreed. It ain’t perfect but a big step forward from separate vals
Kraj razgovora
Novi razgovor -
-
-
Good related article from
@kentcdodds https://kentcdodds.com/blog/make-impossible-states-impossible …, inspired by@DavidKPiano. i really like the phrase "make impossible states impossible" -
applies to databases too: use constraints! a user must have an account: make account_id not nullable and use a foreign key constraint. More direct example: on a posts table, instead of is_draft, is_published, use status: "draft"
Kraj razgovora
Novi razgovor -
-
-
This is the question that I ask myself: at what point do you need a state machine such as XState to handle complex workflow?
-
When you start needing nested states. XState is an implementation of statecharts, which are hierarchical finite state machines. In this graph, "bottom-up" is the code we're typically used to writing.pic.twitter.com/J2f7oAts7D
- Još 3 druga odgovora
Novi razgovor -
-
-
Just watched
@keyframers do something like this
in their draggable calendar episodehttps://youtu.be/jrD7eiRvyvc Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.