There are many operators available, and in order to understand them we need to have a simple way of communicating how they transform a source Observable into a result Observable over time. Throughout this course we are going to see the so-called marble diagrams.

  1. var foo = Rx.Observable.interval(1000);
  2.  
  3. /*
  4.  
  5. foo: ---0---1---2---3--...
  6. multiplyBy(2)
  7. bar: ---0---2---4---6--...
  8.  
  9. */
  10.  
  11. function multiplyBy(multiplier) {
  12. var source = this;
  13. var result = Rx.Observable.create(function subscribe(observer) {
  14. source.subscribe(
  15. function (x) { observer.next(x * multiplier); },
  16. function (err) { observer.error(err); },
  17. function () { observer.complete(); }
  18. );
  19. });
  20. return result;
  21. }
  22.  
  23. Rx.Observable.prototype.multiplyBy = multiplyBy;
  24.  
  25. var bar = foo.multiplyBy(2);
  26.  
  27. bar.subscribe(
  28. function (x) { console.log('next ' + x); },
  29. function (err) { console.log('error ' + err); },
  30. function () { console.log('done'); },
  31. );

[RxJS] Marble diagrams in ASCII form的更多相关文章

  1. [RxJS] Introduction to RxJS Marble Testing

    Marble testing is an expressive way to test observables by utilizing marble diagrams. This lesson wi ...

  2. Reading RxJava Marble Diagrams

    ------>表示一个Observable(承时间推移,由左入右,左边item先发射) ------>上面的图形,表示这个Observable发射的item ------>上的的|( ...

  3. RxJS——Operators

    RxJS 的操作符(operators)是最有用的,尽管 Observable 是最基本的.操作符最基本的部分(pieces)就是以申明的方式允许复杂的异步代码组合简化. 什么是操作符? 操作符是函数 ...

  4. RxJS v6 学习指南

    为什么要使用 RxJS RxJS 是一套处理异步编程的 API,那么我将从异步讲起. 前端编程中的异步有:事件(event).AJAX.动画(animation).定时器(timer). 异步常见的问 ...

  5. RxJS库

    介绍 RxJS是一个异步编程的库,同时它通过observable序列来实现基于事件的编程.它提供了一个核心的类型:Observable,几个辅助类型(Observer,Schedulers,Subje ...

  6. RxJS入门

    一.RxJS是什么? 官方文档使用了一句话总结RxJS: Think of RxJS as Lodash for events.那么Lodash主要解决了什么问题?Lodash主要集成了一系列关于数组 ...

  7. react programming

    So you're curious in learning this new thing called Reactive Programming, particularly its variant c ...

  8. Angular 4+ 修仙之路

    Angular 4.x 快速入门 Angular 4 快速入门 涉及 Angular 简介.环境搭建.插件表达式.自定义组件.表单模块.Http 模块等 Angular 4 基础教程 涉及 Angul ...

  9. 响应式编程(Reactive Programming)(Rx)介绍

    很明显你是有兴趣学习这种被称作响应式编程的新技术才来看这篇文章的. 学习响应式编程是很困难的一个过程,特别是在缺乏优秀资料的前提下.刚开始学习时,我试过去找一些教程,并找到了为数不多的实用教程,但是它 ...

随机推荐

  1. Balsamiq Mockups

    Balsamiq Mockups完全手册 2010.03.18 发布 48,066 浏览 什么是Balsamiq Mockups Balsamiq Mockups出自加利福尼亚州的Balsamiq工作 ...

  2. freeswitch 拨号时添加自定义变量

    Using Channel Variables in Dialplan Condition Statements Channel variables can be used in conditions ...

  3. Apache .htaccess Rewrite解决问号匹配的写法

    如news.asp?id=123 需要把它定向到 news/123.html 这个用 RewriteRule 怎么写啊? RewriteRule ^news\.asp\?id=(\d+)$ news/ ...

  4. WPF的模版

    此例子来自<深入浅出WPF>,刘铁猛. VS2010 源码1:不使用Bingding 源码2:使用Binding 下面展示一些代码: 主窗体XAML代码: <Window x:Cla ...

  5. http server v0.1_http_server.c

    /**************************************************************** filename: http_server.c author: xx ...

  6. [操作系统]iOS6与iOS7屏幕适配技巧

    一.没有包装任何 导航控制器 或者 UITabBarController 1.控制器的view是UIScrollView\UITableView\UICollectionView时(控制器是UITab ...

  7. PHP 7.0 安装使用与性能监测!

    PHP 7.0发布,网上关于新版的介绍很多,介于 7.0 在正式发布之前已经发过若干个 Beta.8个 RC,应该不会出现重大问题.今日我将一台机器升级至 PHP 7.0 并将有关信息记录如下. 本人 ...

  8. 【POJ1067】取石子游戏 (威佐夫博弈)

    [题目] Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的 ...

  9. servlet和struts2一起使用,实现绝对路径下的图片输出到jsp页面

    如果我们在web.xml中配置的struts2的接收请求的路径为: <filter-mapping> <filter-name>struts2</filter-name& ...

  10. Keil C中全局变量的使用

    在KEIL C中,有多个源文件使用到全局变量时,可以在一个源文件中定义全局变量,在另外的源文件中用extern 声明该变量,说明该变量定义在别的文件中,将其作用域扩展到此文件. 例如:有以下两个源文件 ...