博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Cycle.js] The Cycle.js principle: separating logic from effects
阅读量:5213 次
发布时间:2019-06-14

本文共 1335 字,大约阅读时间需要 4 分钟。

The guiding principle in Cycle.js is we want to separate logic from effects. This first part here was logical, and this second part here was effects. Effects are everything that change the external world somehow, the real world such as the DOM is connected to the browser, which is the connected to the user, so when we do something like set the text content, we are changing the screen that will shown to the user. So things like console.log and HTTP network requests, all of these things are effects, and these things live in subscribes.

Logic on the other hand, this is not changing the external world anyhow, it's just an event stream of numbers every second, and we're mapping that event stream to another event stream with strings. This part here is functional, it's all about mapping some primitives to others, and this side is imperatives. Our guiding principle for Cycle.js is we want to push subscribes as far away as we can from our app.

So this part of subscribe we want this to live in the framework, and this part is the only thing that the developer will write as the app. That is the guiding principle to separate logic from effects.

console.clear();// LogicRx.Observable.timer(0,1000).map( i => `Second elapsed ${i}`)// Effect.subscribe( text => console.log(text))

 

转载于:https://www.cnblogs.com/Answer1215/p/5161333.html

你可能感兴趣的文章
设计模式课程 设计模式精讲 2-2 UML类图讲解
查看>>
为块级元素添加链接
查看>>
eclipse Maven Bootstrap 导航栏
查看>>
android studio学习----偏好设置
查看>>
Apache hadoop namenode ha和yarn ha ---HDFS高可用性
查看>>
Silverlight 的菜单控件。(不是 Toolkit的)
查看>>
:hover 鼠标同时触发两个元素变化
查看>>
go语言学习十三 - 相等性
查看>>
Http请求
查看>>
python生成可执行exe文件
查看>>
机器学习入门四------降低损失
查看>>
Idea 提交代码到码云(提交到github也大同小异)
查看>>
医生告诉我们的常识.读完它吧,你会一生受益
查看>>
c#连接excel2007未安装ISAM解决
查看>>
ViewController的.m文件代码布局规范
查看>>
Mono 异步加载数据更新主线程
查看>>
js下拉框联动代码
查看>>
hdu 5017
查看>>
centos安装crontab:
查看>>
升级framework4.0后form认证票据失效的问题
查看>>