[Cycle.js] Main function and effects functions
We need to give structure to our application with logic and effects. This lessons shows how we can organize our code into two parts: main() function for logic, and effects functions for effects.
// Logic (functional)
function main() {
return Rx.Observable.timer(0, 1000)
.map(i => `Seconds elapsed ${i}`);
} // Effects (imperative)
function DOMEffect(text$) {
text$.subscribe(text => {
const container = document.querySelector('#app');
container.textContent = text;
});
} function consoleLogEffect(msg$) {
msg$.subscribe(msg => console.log(msg));
} const sink = main();
DOMEffect(sink);
consoleLogEffect(sink);
[Cycle.js] Main function and effects functions的更多相关文章
- [Cycle.js] Introducing run() and driver functions
Currently the code looks like : // Logic (functional) function main() { return { DOM: Rx.Observable. ...
- The App Life Cycle & The Main Function
The App Life Cycle Apps are a sophisticated interplay between your custom code and the system framew ...
- [Cycle.js] Customizing effects from the main function
How can we show one string on the DOM, and a completely different string on Console log? This lesson ...
- [Cycle.js] Read effects from the DOM: click events
So far we only had effects that write something to the external world, we are not yet reading anythi ...
- [Cycle.js] The Cycle.js principle: separating logic from effects
The guiding principle in Cycle.js is we want to separate logic from effects. This first part here wa ...
- [Cycle.js] Generalizing run() function for more types of sources
Our application was able to produce write effects, through sinks, and was able to receive read effec ...
- [Cycle.js] From toy DOM Driver to real DOM Driver
This lessons shows how we are able to easily swap our toy DOM Driver with the actual Cycle.js DOM Dr ...
- 学习RxJS:Cycle.js
原文地址:http://www.moye.me/2016/06/16/learning_rxjs_part_two_cycle-js/ 是什么 Cycle.js 是一个极简的JavaScript框架( ...
- [Cycle.js] Fine-grained control over the DOM Source
Currently in our main() function, we get click$ event. function main(sources) { const click$ = sour ...
随机推荐
- MODULE_DEVICE_TABLE
1. MODULE_DEVICE_TABLE (usb, skel_table);该宏生成一个名为__mod_pci_device_table的局部变量,该变量指向第二个参数.内核构建时,depmod ...
- $(document).ready(); $().ready(); $()
$(document).ready(function(){}); $().ready(function(){}); $(function(){}), 三者效果是一样的,在文档加载完成之后执行()中的代 ...
- java 后台线层也叫守护线层
import java.util.concurrent.locks.*; class Do9 { public static void main(String[] args) { Ds d=new D ...
- xcode5.1上真机调试报告No architectures to compile for...的解决办法
由于手头上只有一台IPAD一代,近期升级到IOS5.0了(人家apple只让升级到此为止)而开发环境Xcode版本是5.1,默认情况下XCode编译出来的代码最低能跑在IOS6.0下, 于是GOOGL ...
- 深入浅出scanf、getcha、gets、cin函数
转:问题描述一:(分析scanf()和getchar()读取字符) scanf(), getchar()等都是标准输入函数,一般人都会觉得这几个函数非常简单,没什么特殊的.但是有时候却就是因为使用这些 ...
- 手把手教你发布代码到CocoaPods(Trunk方式)-备用
概述 关于CocoaPods的介绍不在本文的主题范围内,如果你是iOS开发者却不知道CocoaPods,那可能要面壁30秒了.直奔主题,这篇文章主要介绍如果把你的代码发布到CocoaPods代码库中, ...
- QT打开网页 QURL
用QT打开一个网页就是先定义一个QUrl对象url,然后利用QDesktopServices::open(url)即可. 例如: const QUrl url(http://www.baidu.com ...
- Keil C调试经验
我们使用Keil C调试某系统时积累的一些经验: 1.由于Keil C对中文支持不太好,因而会出现显示的光标与光标实际所在不一致的现象,这会对修改中文注释造成影响.在Windows2000下面 ...
- PowerShell 中使用json对象的性能比较
PowerShell v3 – Creating Objects With [pscustomobject] – it’s fast! September 19, 2011powershell, v3 ...
- Android Map新用法:MapFragment应用
MapView ,MapActivity 这种的局限在于,必须要继承MapActivity,否则无法使用MapView,但是,MapFragment 这种的局限在于,必须要安装Google Play ...