码迷,mamicode.com
首页 > Web开发 > 详细

[Cycle,js] Customizing effects from the main function

时间:2016-02-02 07:31:44      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

How can we show one string on the DOM, and a completely different string on Console log? This lesson shows how we can make our main function return multiple Observables, each one targeted at a different type of effect.

 

// Logic (functional)
function main() {
  return {
    DOM: Rx.Observable.timer(0, 1000).map( i => `timer is ${i}`),
    Log: Rx.Observable.timer(0, 1000).map(i => 2*i )
  };
i}


function DOMEffect(text$) {
  text$.subscribe(text => {
    const container = document.querySelector(‘#app‘);
    container.textContent = text;
  });
}

function consoleLogEffect(msg$) {
  msg$.subscribe(msg => console.log(msg));
}

const sinks = main();
DOMEffect(sinks.DOM);
consoleLogEffect(sinks.Log);
  

 

[Cycle,js] Customizing effects from the main function

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5176692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!