[RxJS] Reactive Programming - What is RxJS?
2016-03-07 19:54
281 查看
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:
Which is stay in the momery.
But the stream we have:
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:
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);
});
相关文章推荐
- 深入浅出 React Native:使用 JavaScript 构建原生应用
- react native
- React event
- react:undefined is not a function(this.State({flag:true,}))
- React Native-18.React Native 常用API及实践 NetINfo
- ReactJS实用技巧(1):JSX与HTML的那些不同
- 在MAC下配置React-Native开发环境
- react 编写autocomplete实现(非jsx)
- ReactiveCocoa Weak-Strong Dance
- MVVM with ReactiveCocoa
- react jsx 编写autocomplete实现
- [CodeForces 607A]Chain Reaction[DP]
- React 仅仅是你的界限
- 【Android】19.2 ShareActionProvider类—帮你把信息分享出去
- 运行React-Native项目
- 运行React-Native项目
- 在React框架中实现一些AngularJS中ng指令的例子
- react封装二维码
- react native 样式初学~(一)
- React-Native中this的带给大家的困惑