MobX vs. MobX State Tree

问题: Why should I use MobX State Tree over vanilla MobX? It seems like any time I read about MobX, MST is mentioned in the same place. Is anyone actually using just MobX by itse...

问题:

Why should I use MobX State Tree over vanilla MobX? It seems like any time I read about MobX, MST is mentioned in the same place. Is anyone actually using just MobX by itself?

Probably too general of a question...


回答1:

Actually, MST or MobX State Tree is a very descriptive name if you think about it.

MobX is fast, but doesn't provide any organizational structure out of the box, therefore centralized operations like taking snapshots of the whole state, restoring the state from the snapshot, auto synchronizing separated stores, time travel or hot reloading are either not possible or up to developer to support.

MST supports all of the above mentioned (and more) out of the box by organizing separate stores into a single tree of interactive and interacting nodes.

Central in MST (mobx-state-tree) is the concept of a living tree. The tree consists of mutable, but strictly protected objects enriched with runtime type information. In other words, each tree has a shape (type information) and state (data). From this living tree, immutable, structurally shared, snapshots are automatically generated.

However all of these comes at some cost and MST in general is somewhat slower than pure MobX. So if you do not need those features, do not hesitate to use just MobX.

  • 发表于 2019-03-19 02:54
  • 阅读 ( 161 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除