Agera系列《翻译一》

Reactive programming(响应式编程)

    Agera uses the well-known observer pattern as the driving mechanism behind its reactive programming paradigm. 
An observer is represented by the interface Updatable, can be registered to and deregistered from Observable objects, and reacts to the events by updating itself, hence the name.
The remainder of this wiki uses the word observable and updatable as nouns, to refer to Java objects implementing these two interfaces, respectively.

    Agrea响应式编程使用知名的观察者模式作为驱动模式。
    一个被观察者(实现了Observable接口)广播事件给所有的观察者。
    一个观察者(实现了Updatable接口)可以在被观察者那里注册和注销,通过更新自己对events做出反映,因此而得名。

    接下来各自使用observable(被观察者)和updatable(观察者)两个接口。

Push event, pull data(Push 事件,pull数据)

    Agera uses a push event, pull data model. 
    This means that the events do not carry any data, and that an updatable is responsible for (re-) fetching data from its data source dependency when performing self-updates, if/when necessary.
    Agera使用push事件,pull数据的模型。
    这意味着事件不携带任何数据,当观察者需要执行更新操作时,updatable负责任的从他的数据依赖源取来数据。

    In this way, the data supplying responsibility is removed from the Observable interface, allowing it to encapsulate simple events like a button click,
     a pull-to-refresh trigger, a signal to re-sync (sent to the app as a GCM message), etc.

    这么说来,负责供应的数据从被观察者接口移除,允许封装简单的事件:按钮点击,下拉刷新,发送GSM消息等等。

        However, observables commonly also supply data. An observable that supplies data and defines an event as a change of the supplied data is called a Repository. 
        This does not change the push event, pull data model: the repository notifies the registered updatables to update themselves when the data changes; and the updatables pull data from the repository when they individually react to this event. 
        One benefit of this model is that the data consumption is separate from the event dispatch, allowing the repository to perform lazy calculation.
    无论如何,被观察者通常提供数据。被观察者提供数据和定义事件作为一次改变提供数据被称为仓库。这个不会改变push事件,pull数据模型:仓库通知注册了updatables的观察者去更新当数据变化时,同时观察者从仓库获取到数据当他们独自的做出反应对这些事件。这个模型的好处是:数据消费和事件分发是分开的,允许仓库执行懒计算。

    Due to the push event, pull data model and the general multi-threaded handling, an updatable may not see the full change history of a repository’s data.
     This is by design: in most cases (particularly for updating the app’s UI), only the latest, most up-to-date data should matter.
    由于这个push事件,pull数据模型和普通的多线程处理,一个观察者或许不能看到仓库数据的所有的改变历史。这是按设计:在多数情况下,只有最后的数据会才是重要的。
    The standard implementation of a reactive client in the Agera style consists of the following:  
1. Register an updatable to the appropriate observables that notify of events of relevance;
2. Optionally manually invoke the updatable to initialize or correct any client state;
3. Wait for the updatable to be invoked by any observable, and when invoked, update the client state as necessary using data newly pulled from the data sources;
4. Unregister the updatable from the same set of observables when reaction is no longer needed.
        实现了标准响应式编程使用Agera模式有如下事件组成:
1. 注册一个观察者到合适的被观察者,通知相关的事件。
2. 选择手动初始化或纠正任何客户端状态更新
3. 当被观察者通知观察者,使用数据源的最新数据更新client状态
4. 当不需要监测时,注销通知。

不断完善中。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值