Knockout.js 和 Rx.js 有什么区别?

发布于 2024-10-19 06:07:21 字数 289 浏览 5 评论 0原文

有谁知道 RxJs 和 < a href="http://knockoutjs.com/" rel="noreferrer">淘汰赛?对我来说,表面上他们似乎在试图解决同样的问题,构建一个事件驱动的 UI。但是对于两者都有过经验的人来说,它们有何不同/有何相似之处?你能描述一下他们的一些情况来帮助我选择吗?

Does anyone know the differences between RxJs and Knockout? To me on the surface they seem to be trying to solve the same problem, to build an event driven UI. But someone who has had experience with both, how do they differ/ how are they similar? Can you describe something about them to help me choose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仄言 2024-10-26 06:07:21

Steve(Knockout 的创建者)在他的博客上解释了差异

我非常熟悉 Rx for JavaScript,最近使用过它
重点关注一个大项目,实际上是设计的各个方面
淘汰赛是根据我的 Rx 经验进行的。

主要区别
Knockout 的观察者模式实现与 Rx 的实现之间是
Knockout 自动推断关联和依赖关系
在常规程序代码的可观察量之间,无需您
通过特殊的功能 API 预先指定它们。我想要
淘汰使用常规过程/命令式代码,因为它更多
大多数开发人员都熟悉且平易近人。

另一个区别是
Rx 针对组合无状态事件流进行了优化。在
首先我对这个及其功能纯度很感兴趣,但是
一段时间后,我感觉越来越像是在跳跃
尴尬的箍,不得不发明额外的方法来模拟状态来管理
高效的 UI 命令。这就是为什么在淘汰赛中,所有可观察量都可以
被视为有状态的 - 例如,您始终可以阅读他们的最新内容
值(顺便说一句,它被缓存 - 它不会重新计算,直到
基础数据更改)。

Rx 比淘汰赛更进一步进入高级阶段
组合事件流的方式,而 Knockout 比 Rx 更进一步
进入 UI 开发,让您将其可观察值绑定到 HTML DOM
元素和模板并以您想要的方式操作它们。接收方是
很擅长它的功能,但结果并不完全是我想要的
构建丰富的 UI - 因此就有了 Knockout 的设计。

Steve (the creator of Knockout) explained the difference on his blog:

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

The key difference
between Knockout’s implementation of the observer pattern and Rx’s is
that Knockout automatically infers the associations and dependencies
between observables from regular procedural code without you having to
specify them up front though a special functional API. I wanted
Knockout to use regular procedural/imperative-style code as it’s more
familiar and approachable for most developers.

Another difference is
that Rx is optimised for composing streams of events without state. At
first I was enthusiastic about this and its functional purity, but
after some time it felt increasingly like I was jumping through
awkward hoops and had to invent extra ways to simulate state to manage
UI commands efficiently. That’s why, in Knockout, all observables can
be treated as stateful - for example you can always read their latest
value (which is cached, by the way - it doesn’t recompute until the
underlying data changes).

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

痴骨ら 2024-10-26 06:07:21

它们实际上是完全不同的框架,但我可以理解为什么您会看到交叉:

RxJs 提供了一种针对异步流(如事件和 Web 请求)组合操作的方法,并包括高级场景(如组合流) (当 A 和 B 都发生时,启动它,但如果 A 或 B 再次发生则取消它)

Knockout 是一个 MVVM 框架,允许您通过映射用户界面的模型来管理用户界面的状态功能。这允许您的视图逻辑与您的视图分离。

They're actually quite different frameworks, though I can see why you'd see crossover:

RxJs provides a means of composing operations against asynchronous streams, like events and web requests, and includes advanced scenarios like combining streams (when both A and B occur, start this, but cancel it if A or B occur again)

Knockout is an MVVM framework that allows you to manage the state of your user interface via a model that maps it's functionality. This allows your view's logic to be separated from your view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文