gpt4 book ai didi

knockout.js - Knockout.js 和 Rxjs 有什么区别?

转载 作者:行者123 更新时间:2023-12-03 06:35:00 24 4
gpt4 key购买 nike

有谁知道 RxJs 之间的区别和 Knockout ?对我来说,表面上他们似乎在试图解决同样的问题,构建一个事件驱动的 UI。但是对于两者都有过经验的人来说,它们有何不同/有何相似之处?你能描述一下他们的一些情况来帮助我选择吗?

最佳答案

史蒂夫(Knockout 的创建者)explained the difference在他的博客上:

I’m very familiar with Rx for JavaScript, having recently used itheavily on a big project, and in fact aspects of the design ofKnockout are made with my Rx experiences in mind.

The key differencebetween Knockout’s implementation of the observer pattern and Rx’s isthat Knockout automatically infers the associations and dependenciesbetween observables from regular procedural code without you having tospecify them up front though a special functional API. I wantedKnockout to use regular procedural/imperative-style code as it’s morefamiliar and approachable for most developers.

Another difference isthat Rx is optimised for composing streams of events without state. Atfirst I was enthusiastic about this and its functional purity, butafter some time it felt increasingly like I was jumping throughawkward hoops and had to invent extra ways to simulate state to manageUI commands efficiently. That’s why, in Knockout, all observables canbe treated as stateful - for example you can always read their latestvalue (which is cached, by the way - it doesn’t recompute until theunderlying data changes).

Rx goes further than Knockout into advancedways of composing event streams, whereas Knockout goes further than Rxinto UI development, letting you bind its observables to HTML DOMelements and templates and manipulate them any way you want. Rx isgreat at what it does but turned out not be be exactly how I wanted tobuild rich UIs - hence the design of Knockout.

关于knockout.js - Knockout.js 和 Rxjs 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5101113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com