MobX v2.3.0 發布,一個 TFRP 編程范式的實現
MobX
官網:
開源地址:https://github.com/mobxjs/mobx
要想知道MobX是什么,首先需要了解一下FRP是什么,FRP 的本質是,在聲明一個值的時候,同時指定他的動態行為。這個值可能是事件,也可能是數據。 FRP 有兩個重要的分支:
- 基于 Event Stream 的 FRP
基于 Event Stream 的 FRP 擅長于管理 Stream,可進行 Joining, splitting, merging, mapping, sampling 等等。在需要處理多個 Event Stream 的時候非常有用,但對于簡單場景來說,就過于復雜了。比如 RxJS 和 BaconJS 就屬于此類。
- Transparent FRP (TFRP)
Transparent FRP 是在背后去實現 Reactive Programming 。和 Event Stream 的 FRP 一樣,TFRP 會在需要的時候更新 View,不同的是 TFRP 不需要你定義如何 (How) 以及何時 (When) 更新。這一類型的框架有 Meter(Tracker),knockoutJS 和 EmberJS 。
接下來介紹一下Mobx 和 其他實現有什么不同:
- 同步執行 (這樣監聽的值始終是最新的,并且調試會方便,因為沒有額外的 Promise/Async 庫引入的堆棧信息)
- 沒有引入額外的數據結構,基于普通的 Object, Class, Array 實現 (更少學習成本,更新數據時更自然)
- 獨立方案 (不捆綁框架,相比 Meter, EmberJS 和 VueJS 而言)
更新日志
語義變化
@observable
is now always defined on the class prototypes and not in the instances. This means that@observable
properties are enumerable, but won't appear ifObject.keys
orhasOwnProperty
is used on a class instance.- Updated semantics of
reaction
as discussed in#278
. The expression now needs to return a value and the side effect won't be triggered if the result didn't change.asStructure
is supported in these cases. In contrast to MobX 2.2, effects will no longer be run if the output of the expression didn't change.
功能增強
- Introduces
isAction(fn)
#290 - If an (argumentless) action is passed to
observable
/extendObservable
, it will not be converted into a computed property. - Fixed #285: class instances are now also supported by
toJS
. Also members defined on prototypes which are enumerable are converted. - Map keys are now always coerced to strings. Fixes #308
when
,autorun
andautorunAsync
now accept custom debug names (see #293, by @jamiewinder)- Fixed #286: autorun's no longer stop working if an action throws an exception
- Implemented
runInAction
, can be used to create on the fly actions (especially useful in combination withasync/await
, see #299 - Improved performance and reduced mem usage of decorators signficantly (by defining the properties on the prototype if possible), and removed subtle differences between the implementation and behavior in babel and typescript.
- Updated logo as per #244. Tnx @osenvosem!
下載
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!