接收的真实世界的例子 [英] Real world examples of Rx

查看:162
本文介绍了接收的真实世界的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  良好的反应扩展使用的例子

我一直在玩与周围的反应延长了一小会儿了,但大多局限于处理/在一个WPF前端组成的用户驱动的事件。

这是做异步编程的这样一个强大的,新的方式,我很好奇,别人都在做它,并在你认为它可能是能够改善我们目前正在做的事情的方式呢?

解决方案

我们使用RX上两个项目(Silverlight的用户界面)已经取得巨大成功

。在开始的意图是为了<一个href="http://stackoverflow.com/questions/2745462/best-practice-for-using-wcf-service-by-silverlight/2745781#2745781">simplify WCF的接入层)理性的是,在最坏的情况下,我们总是可以恢复到做事情的标准(回调)的方式,而不会影响更高层次的用户界面。

没想到,我们知道RX就像是一种成瘾药物 - 一旦你开始使用它那里根本没有回来。像病毒一样很快■从这种低层次的通信层$ P $垫一路攀升到UI组件:

  • 我们开始用简单的语法糖,可以让访问WCF服务的简单。
  • 从那里,这是一个自然的一步RX扩展到服务器到客户端的异步通讯
  • 后,要使用RX合并这两种方式对于客户端与服务器通信为一个,这样的ViewModels是不可知他们是如何得到的消息是默认选项。

,然后将其完全投降:

  • 需要处理的消息传出来的秩序?
  • 需要刷新一个单元格时,价格变化的电网?
  • 有性能问题,因为客户端从服务器的邮件轰炸?
  • 有一些残留的CEP逻辑来处理?

好了,你猜怎么着,有RX运营商的那次)(如果有没有 - 你可以很容易地只写一个)

这一切的最困难的部分是要克服我的脑,伤害那么糟糕的感觉,每个人都对我们的团队经验丰富的开头。一个凡人多年手柄 - 我的事件按这个回调编码空调的大脑只是没有有线RX看世界的方式。其结果是RX code(特别是当它逐渐得到越来越在处理更密集的越来越复杂的情况下)对于未prepared头脑的样子完整的胡言乱语说可笑不导致兔子掏出一个看似空帽子。不幸的是,现实是运行code,因此整个团队就没有地方魔法生产必须要在船上,这意味着每个人都必须要经过重新布线他们的大脑在这个痛苦的过程是什么,似乎首先是一个非常不自然方法。

我会说,这是一个人为因素,而不是RX API本身是有效地采用RX的最大障碍。但男孩是值得的!

Possible Duplicate:
Good example of Reactive Extensions Use

I've been playing around with the Reactive Extension for a little while now, but mostly limited to handling/composing user driven events within a WPF frontend.

It's such a powerful, new way of doing async programming, and I'm curious as to what other people are doing with it, and where do you think it might be able to improve the way we're currently doing things?

解决方案

We used RX with great success on two projects (Silverlight UI) already. At the beginning the intent was to simplify the WCF access layer) The rational was that in the worse case scenario we can always revert back to standard (callback) ways of doing things without affecting higher levels of the UI.

Little did we know that RX is like an addictive drug - once you start using it there's simply no coming back. Like a virus it quickly spread from this low-level communication layer all the way up to UI components:

  • we started with simple syntactic sugar to make accessing WCF services simpler.
  • from there it was a natural step to extend RX to server-to-client async messaging
  • after that to use RX to merge both of these ways for client to communicate with the server into one so viewmodels are agnostic about how they receive messages was a default option.

And then it was complete capitulation:

  • need to handle messages coming out of order?
  • need to flash a cell on the grid when price changes?
  • have a performance issue because client is bombarded by messages from the server?
  • have some rudimental CEP logic to handle?

Well, guess what, there's RX operator for that ;) (and if there's not - you can easily just write one)

The hardest part of it all was to overcome that "my-brain-hurts-so-bad" feeling that everyone on our team experienced at the beginning. Brain of a mere mortal conditioned by years of handle-my-event-by-this-callback coding is just not wired the way RX sees the world. As the result RX code (especially once it progressively gets more and more dense while handling more and more complicated scenarios) for an unprepared mind looks like complete abracadabra that amusingly does result in a rabbit pulled out of a seemingly empty hat. Unfortunately, the reality is there's no place for magic in production running code and thus whole team must be on board, which means everyone will have to go through this painful process of rewiring their brains in what seems at first like a very unnatural way.

I'd say that it's a human factor and not the RX API itself that is the biggest obstacle on effectively adopting RX. But boy is it worth it!

这篇关于接收的真实世界的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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