原文
| ||||||||||||||||||
| ||||||||||||||||||
![]() |
原始链接: https://news.ycombinator.com/item?id=43615624
Hacker News讨论总结: 文章“在React中 {Transitions} = F(state)”讨论了如何将React应用视为状态机的模型,其中UI是状态的函数 (UI = f(state))。然而,dfabulich认为,将复杂的应用正式地建模为状态机,特别是用图表表示,通常是不切实际的,且价值不大。状态机图在状态和转换数量超过一定程度后会变得笨拙且无用。React的优势在于将UI视为状态的纯函数,这比管理复杂的状态图更有效。这是一个更简单有效的模型。 dvtkrlbs补充道,在真实的React应用中,组件经常依赖于上下文和第三方资源,使得纯粹的UI = f(state)范式并不总是直接适用,尽管对于实际的视图组件来说,这是一个有益的方法。
| ||||||||||||||||||
| ||||||||||||||||||
![]() |
Not really, though. While you _can_ model any program as a state machine, doing so typically adds nothing to your understanding of the program.
State-machine diagrams are especially useless. A diagram is only useful if it has about a dozen things in it, maybe two dozen, maximum. But that doesn't mean you can model a dozen _states_ in a state-machine diagram; in these diagrams, the _transitions_, the arrows between the states, are at least as important as the states themselves. So the diagrams are useless when the number of states + the number of transitions between them are greater than a few dozen. Typically that means state diagrams are only with a handful of states with a few transitions hanging off of each.
But, if your problem is simple enough that you can represent it with a handful of states with two or three transitions each, then you have a _very_ trivial problem, so trivial that the state-machine diagram likely added nothing at all to your understanding of it.
This is why no UI frameworks actually _do_ model UI as a set of states with transitions. It's easier to model the _state diagram_ as a _function_ and then just forget about the state diagram.
That's what React is all about! A pure function, UI = f(state). It's _better_ than a state diagram.
This article is saying: "Hey, you could think of React, something conceptually simple, as something unnecessarily complicated, instead!" Gee, thanks?
reply