首页 > Web开发 > 详细

[Cycle.js] Main function and effects functions

时间:2016-02-02 07:30:02      阅读:137      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/5176690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!