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的更多相关文章

  1. [Cycle.js] Introducing run() and driver functions

    Currently the code looks like : // Logic (functional) function main() { return { DOM: Rx.Observable. ...

  2. The App Life Cycle & The Main Function

    The App Life Cycle Apps are a sophisticated interplay between your custom code and the system framew ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. [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 ...

  8. 学习RxJS:Cycle.js

    原文地址:http://www.moye.me/2016/06/16/learning_rxjs_part_two_cycle-js/ 是什么 Cycle.js 是一个极简的JavaScript框架( ...

  9. [Cycle.js] Fine-grained control over the DOM Source

    Currently in our main() function,  we get click$ event. function main(sources) { const click$ = sour ...

随机推荐

  1. LDAP索引及缓存优化

    一.设置索引 索引将查找信息和 Directory Server 条目关联起来. Directory Server支持以下几种索引: 1出现索引 (pres) - 列出了具有特定属性的条目,与属性的值 ...

  2. (转)ASP.NET MVC 学习第一天

    天道酬勤0322   博客园 | 首页 | 发新随笔 | 发新文章 | 联系 | 订阅  | 管理 随笔:10 文章:0 评论:9 引用:0 ASP.NET MVC 学习第一天 今天开始第一天学习as ...

  3. [c#]asp.net开发微信公众平台(2)多层架构框架搭建和入口实现

    上篇已经设计出比较完善的数据库了,这篇开始进入代码.  首先把上篇设计的数据库脚本在数据库中执行下,生成数据库,然后在VS中建立项目,为了方便理解和查看,我设计的都是很直白的类名和文件名,没有命名空间 ...

  4. url编码方法(暂时知道是什么

    var a="https://i.cnblogs.com/EditPosts.aspx?opt=1" encodeURI(a); encodeURIComponent(); dec ...

  5. 2016/01/10 C++ Primer 小记 —— 命令行编译环境配置

    OK!第一篇博文!自贺一下! 今日看了此书的前几页.嗯,说得挺全,基础易懂. 之前学过c++,但没用过命令行编译. 本人用的VS里的编译器,文件名是cl.exe,在VC目录下. 虽然有了编译器,但并不 ...

  6. 轻量级jQuery工具提示插件tooltipsy使用方法

    今天想给单位的系统弄一个提示插件,懒得自己做,于是就上网百度了几个jQuery插件,挺好用的.下面以tooltipsy插件为例,说明如何使用这些插件. 一.下载 首先到tooltipsy的官网http ...

  7. html5 画布上的rotate使用

    作为刚进公司的毕业生,第一个项目便是开发html5游戏,于是网上搜寻各种有关html5的资料,把w3School中有关html5的教程通通过了一遍,发现里面的教程非常适合刚接触html5的人,作为菜鸟 ...

  8. 使用PyQt4写界面后台程序方法总结

    使用PyQt4编写界面后台程序的方法总结 一.怎么建立多线程 界面程序如果有稍微耗时一点的任务如果不使用多线程就会界面卡死,所以大多数情况会使用到多线程.PyQt4自己有多线程的机制,可以派生多线程类 ...

  9. Gson JsonParser的使用

    package iotest; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gso ...

  10. HTTP协议细节

    一]客服端  -->  服务端        1>结构            a)请求行            b)请求头            c)请求体:请求的内容,如果没有,就是空白 ...