要求对 Reactive Extensions (RX) 进行清晰、如画的解释? [英] Requesting a clear, picturesque explanation of Reactive Extensions (RX)?

查看:42
本文介绍了要求对 Reactive Extensions (RX) 进行清晰、如画的解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间以来,我一直试图将头放在 RX 上.而且,说实话,我永远不确定我是否得到了它 - 或没有.

For a long time now I am trying to wrap my head around RX. And, to be true, I am never sure if I got it - or not.

今天在http://reactive-extensions.github.com/RxJS/上找到了一个解释- 在我看来 - 太可怕了.它说:

Today, I found an explanation on http://reactive-extensions.github.com/RxJS/ which - in my opinion - is horrible. It says:

RxJS 之于事件,就像 Promise 之于异步.

RxJS is to events as promises are to async.

太好了.这是一个充满复杂性的句子,如果你对RX是什么一无所知,那么在这句话之后你就和以前一样愚蠢了.

Great. This is a sentence so full of complexity that if you do not have the slightest idea of what RX is about, after that sentence you are quite as dumb as before.

这基本上是我的问题:你在常见地方找到的关于 RX 的所有解释都让(至少我)感到愚蠢.他们将 RX 解释为一个高度复杂的概念,其中包含很多高度复杂的单词和术语等等,而我从来不太确定它是关于什么的.

And this is basically my problem: All the explanations in the usual places you find about RX make (at least me) feel dumb. They explain RX as a highly sophisticated concept with lots of highly complicated words and terms and whatsoever, and I am never quite sure what it is about.

所以我的问题是:你会如何向一个五岁的人解释 RX?我想要一个清晰、如画的解释,说明它是什么、它有什么好处以及它的主要概念是什么?

So my question is: How would you explain RX to someone who is five years old? I'd like a clear, picturesque explanation of what it is, what it is good for, and what its main concepts are?

推荐答案

所以,LINQ(在 JavaScript 中,这些是高级数组方法,例如 mapfilterreduce 等 - 如果您不是 C# 开发人员,只要我提到LINQ"就替换它)为您提供了一堆可以应用于 Sequences 的工具(粗略意义上的列表"),以便过滤输入并将其转换为输出(又名我真正感兴趣的列表").但什么是列表?

So, LINQ (in JavaScript, these are high-level array methods like map, filter, reduce, etc - if you're not a C# dev, just replace that whenever I mention 'LINQ') gives you a bunch of tools that you can apply to Sequences ("Lists" in a crude sense), in order to filter and transform an input into an output (aka "A list that's actually interesting to me"). But what is a list?

列表,是一些元素,以特定的顺序.我可以使用任何列表并将其转换为更好的 LINQ 列表.

A List, is some elements, in a particular order. I can take any list and transform it into a better list with LINQ.

(不一定是排序顺序,而是一个顺序).

(Not necessarily sorted order, but an order).

但是事件呢?让我们订阅一个事件:

But what about an Event? Let's subscribe to an event:

OnKeyUp += (o,e) => Console.WriteLine(e.Key)
>>> 'H'
>>> 'e'
>>> 'l'
>>> 'l'
>>> 'o'

嗯.这看起来像某些事情,以特定的顺序.你现在突然明白了,列表和事件是一回事!

Hm. That looks like some things, in a particular order. It now suddenly dawns upon you, a list and an event are the same thing!

...那我为什么不能将输入的事件转换和过滤成更有趣的事件.这就是 Rx.它采用您所知道的关于处理序列的所有知识,包括所有 LINQ 运算符,如 Select、Where 和 Aggregate,并将它们应用于事件.

...then why can't I transform and filter input events into more interesting events. That's what Rx is. It's taking everything you know about dealing with sequences, including all of the LINQ operators like Select and Where and Aggregate, and applies them to events.

简单易行.

回调不是基本上只发生一次的事件吗?它不是基本上就像一个带有一个项目的 List 吗?事实证明是这样,关于 Rx 的一件有趣的事情是它让我们用相同的语言处理事件和回调(以及诸如地理定位请求之类的东西)(即我们可以将两者结合起来,或者等待以太之一或另一个,等等等等).

Isn't a Callback just basically an Event that only happens once? Isn't it basically just like a List with one item? Turns out it is, and one of the interesting things about Rx is that it lets us treat Events and Callbacks (and things like Geolocation requests) with the same language (i.e. we can combine the two, or wait for ether one or the other, etc etc).

这篇关于要求对 Reactive Extensions (RX) 进行清晰、如画的解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆