功能反应编程对事件监听器的优势 [英] Advantage of Functional Reactive Programming over event-listeners

查看:132
本文介绍了功能反应编程对事件监听器的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经听到很多关于功能反应式编程的信息,并且决定检查一下大事件。通过bacon.js文档,主要区别在于,不是在组件上设置事件侦听器,而是在其上创建一个事件流,并将事件处理程序传递给流。换句话说,我所做的只是将事件处理程序从组件移动到事件流。是吗如果是这样,那么这样做有什么好处?

I've been hearing a lot about functional reactive programming, and decided to check out what the big deal is. Going through the bacon.js documentation, it seems that the main difference is that instead of setting an event listener on a component, I create an event stream on it, and pass the event handler into the stream instead. In other words, all I really did was move the event handler from the component to the event stream. Is that it? If so, what's the big advantage of doing this?

推荐答案


是吗? >

Is that it?

否。这是关于具有事件流。您仍然会将听众附加到他们,以执行效果,但在源和目的地之间,您有一个非常强大的抽象。

No. It's about having event streams. You still will attach listener to them in the end to execute effects, but between the source and the destination you've got a very mighty abstraction.


这样做的最大优点是什么?

what's the big advantage of doing this?

事件流具有很多更高级的功能来轻松处理它们,并且撰写它们,而不会写出所有容易出错的样板代码。

The event streams do have lots of higher-order functions to easily deal with them, and for composing them without writing out all the error-prone boilerplate code.

As 这些文件说得很好,培根

As the docs put it quite nicely, bacon


将你的事件意大利面变成<强化>清洁和声明培养,从强制转为功能性。这就像用 map filter -loops的嵌套 C $ C>。停止处理单个事件,并使用事件流。将您的数据与合并组合 [和操作]较重的武器[like] flatMap combineTemplate

turns your event spaghetti into clean and declarative feng shui bacon, by switching from imperative to functional. It's like replacing nested for-loops with functional programming concepts like map and filter. Stop working on individual events and work with event streams instead. Combine your data with merge and combine [and wield] heavier weapons [like] flatMap and combineTemplate.

这篇关于功能反应编程对事件监听器的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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