zoukankan      html  css  js  c++  java
  • [RxJS] Reactive Programming

    First thing need to understand is, Reactive programming is dealing with the event stream.

    Event streams happens overtime, which not stay in the memory.

    For example, the array we have:

    var source = ['1', '1', 'foo', '2', '3', '5', 'bar', '8', '13'];

    Which is stay in the momery. 

    But the stream we have:

    let logic = Rx.Observable.interval(400).take(9)
      .map( (i) => {
        let val = ['1', '1', 'foo', '2', '3', '5', 'bar', '8', '13'][i]
        return parseInt(val, 10);
    })

    Which happens overtime, every 400ms it return an Interge if possible.

    So the main difference between array stay in memory and the events streams is array already stay in memory and the streams happens overtime.

    But the nice things about the stream is we can still use the methods we have for array:

    let logic = Rx.Observable.interval(400).take(9)
      .map( (i) => {
        let val = ['1', '1', 'foo', '2', '3', '5', 'bar', '8', '13'][i]
        return parseInt(val, 10);
    })
      .filter( (number) => {
        return !isNaN(number)
      })
      .reduce( (acc, y) => {
         return acc + y;
      } );
    
    let effect = logic.subscribe( (number) => {
      console.log(number);
    });
  • 相关阅读:
    TP-LINK WR941N路由器研究
    thinkjs初试
    记浏览器帐号登录插件开发遇到的问题
    你被adblock坑过吗?
    web应用,我们需要了解什么?
    算法之合并排序
    算法之插入排序
    算法之初体验
    nodejs学习笔记之网络编程
    炫酷吊炸天的nodeppt
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5251686.html
Copyright © 2011-2022 走看看