MobX v2.3.0 发布,一个 TFRP 编程范式的实现

jopen 8年前
   <p><strong>MobX</strong></p>    <p>官网:</p>    <p>开源地址:<a href="/misc/goto?guid=4958991392500314719">https://github.com/mobxjs/mobx</a></p>    <p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/a1a245dcc1cfb8d1a1a54ac44c695ab0.png" /></p>    <p>要想知道MobX是什么,首先需要了解一下FRP是什么,FRP 的本质是,在声明一个值的时候,同时指定他的动态行为。这个值可能是事件,也可能是数据。 FRP 有两个重要的分支:</p>    <ul>     <li>基于 Event Stream 的 FRP<br /> 基于 Event Stream 的 FRP 擅长于管理 Stream,可进行 Joining, splitting, merging, mapping, sampling 等等。在需要处理多个 Event Stream 的时候非常有用,但对于简单场景来说,就过于复杂了。比如 RxJS 和 BaconJS 就属于此类。<br />  </li>     <li>Transparent FRP (TFRP)<br /> Transparent FRP 是在背后去实现 Reactive Programming 。和 Event Stream 的 FRP 一样,TFRP 会在需要的时候更新 View,不同的是 TFRP 不需要你定义如何 (How) 以及何时 (When) 更新。这一类型的框架有 Meter(Tracker),knockoutJS 和 EmberJS 。</li>    </ul>    <p>接下来介绍一下Mobx 和 其他实现有什么不同:</p>    <ul>     <li>同步执行 (这样监听的值始终是最新的,并且调试会方便,因为没有额外的 Promise/Async 库引入的堆栈信息)</li>     <li>没有引入额外的数据结构,基于普通的 Object, Class, Array 实现 (更少学习成本,更新数据时更自然)</li>     <li>独立方案 (不捆绑框架,相比 Meter, EmberJS 和 VueJS 而言)</li>    </ul>    <p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/f5c1e529ee681e2ae4e086c4da195838.png" /> </p>    <h2>更新日志</h2>    <h3>语义变化</h3>    <ul>     <li><code>@observable</code> is now always defined on the class prototypes and not in the instances. This means that <code>@observable</code>properties are enumerable, but won't appear if <code>Object.keys</code> or <code>hasOwnProperty</code> is used on a class <em>instance</em>.</li>     <li>Updated semantics of <code>reaction</code> as discussed in <code>#278</code>. The expression now needs to return a value and the side effect won't be triggered if the result didn't change. <code>asStructure</code> 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.</li>    </ul>    <h3>功能增强</h3>    <ul>     <li>Introduces <code>isAction(fn)</code> #290</li>     <li>If an (argumentless) action is passed to <code>observable</code> / <code>extendObservable</code>, it will not be converted into a computed property.</li>     <li>Fixed #285: class instances are now also supported by <code>toJS</code>. Also members defined on prototypes which are enumerable are converted.</li>     <li>Map keys are now always coerced to strings. Fixes #308</li>     <li><code>when</code>, <code>autorun</code> and <code>autorunAsync</code> now accept custom debug names (see #293, by @jamiewinder)</li>     <li>Fixed #286: autorun's no longer stop working if an action throws an exception</li>     <li>Implemented <code>runInAction</code>, can be used to create on the fly actions (especially useful in combination with <code>async/await</code>, see #299</li>     <li>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.</li>     <li>Updated logo as per #244. Tnx @osenvosem!</li>    </ul>    <h2>下载</h2>    <ul>     <li><a href="/misc/goto?guid=4958991392620745145" rel="nofollow"><strong>Source code</strong> (zip)</a></li>     <li><a href="/misc/goto?guid=4958991392708613174" rel="nofollow"><strong>Source code</strong> (tar.gz)</a></li>    </ul>    <h2> </h2>