Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobX 和 TFRP #4

Open
sorrycc opened this issue Jun 3, 2016 · 1 comment
Open

MobX 和 TFRP #4

sorrycc opened this issue Jun 3, 2016 · 1 comment
Labels

Comments

@sorrycc
Copy link
Owner

sorrycc commented Jun 3, 2016

MobX 是一个 TFRP 编程范式的实现实现。

那什么是 TFRP?

FRP

要知道 TFRP,就得先了解 FRP 。先看 FRP 的定义:

The essence of functional reactive programming is to specify the dynamic behavior of a value completely at the time of declaration.
-- Heinrich Apfelmus

所以,FRP 的本质是,在声明一个值的时候,同时指定他的动态行为。这个值可能是事件,也可能是数据。

分支

然后 FRP 有两个重要的分支:

  1. 基于 Event Stream 的 FRP
  2. Transparent FRP (TFRP)

基于 Event Stream 的 FRP 擅长于管理 Stream,可进行 Joining, splitting, merging, mapping, sampling 等等。在需要处理多个 Event Stream 的时候非常有用,但对于简单场景来说,就过于复杂了。比如 RxJS 和 BaconJS 就属于此类。

Transparent FRP 是在背后去实现 Reactive Programming 。和 Event Stream 的 FRP 一样,TFRP 会在需要的时候更新 View,不同的是 TFRP 不需要你定义如何 (How) 以及何时 (When) 更新。这一类型的框架有 Meter(Tracker),knockoutJS 和 EmberJS 。

那么已经有这么多实现了,为什么还要有 Mobx ?

Mobx

Mobx 和其他实现有些不同。

  1. 同步执行 (这样监听的值始终是最新的,并且调试会方便,因为没有额外的 Promise/Async 库引入的堆栈信息)
  2. 没有引入额外的数据结构,基于普通的 Object, Class, Array 实现 (更少学习成本,更新数据时更自然)
  3. 独立方案 (不捆绑框架,相比 Meter, EmberJS 和 VueJS 而言)

深入

更多关于 FRP 的资料:

Tracker 文档:

@sorrycc sorrycc changed the title Mobx 和 TFRP MobX 和 TFRP Jun 3, 2016
@benjycui
Copy link

benjycui commented Jun 3, 2016

Reactive Programming 的另一个参考文档 https://github.com/benjycui/introrx-chinese-edition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants