We have been using Observable.create() a lot in previous lessons, so let's take a closer look how does it work.

The create function:

var foo = Rx.Observable.create( function(observer){
observer.next();
observer.next();
observer.next();
observer.complete();
}) ; foo.subscribe(
(x)=>{console.log('next ' + x);},
(err)=>{console.log('err ' + err);},
()=>{console.log('done');},
)

In deep, create() function equal to new Rx.Observable():

var foo = new Rx.Observable( function(observer){
observer.next();
observer.next();
observer.next();
observer.complete();
}) ;

And this also equal to:

function subscribe(observer){
observer.next();
observer.next();
observer.next();
observer.complete();
} var foo = new Rx.Observable( subscribe );

So, if we get rid of RxJS, then we can create the create() function like:

function subscribe(observer){
observer.next();
observer.next();
observer.next();
observer.complete();
} var observer = {
next: (x)=>{console.log('next ' + x);},
error: (err)=>{console.log('err ' + err);},
complete: ()=>{console.log('done');}
} subscribe(observer);

Of course, it's useful to have the observable type because then it has all those nice operators that we saw and that we are also seeing new operators coming next. If you paid attention, then you're going to remember that in the subscribe, we had previously three functions here as argument. Instead of an object, as we have now, we had just these three functions.

Also, the observable type, it converts these three functions into an observer object. Before it calls this, it will actually take these three functions and put labels in front of them like that, to create the observer object. It's normalizing it.

最新文章

  1. UIScrollView之轮转图片
  2. i++问题
  3. Java Hour 42 fastjson
  4. Javascript offsetLeft详情
  5. dtGrid插件集成到Angular环境实现表格化数据展现
  6. 易语言转C#小试牛刀
  7. 在SQL Server中对视图进行增删改
  8. android调用js
  9. Prolog 外部不能有 DOCTYPE 声明。处理资源 'http://192.168.115.152:8082/api/EmpApi.aspx' 时出错。第 3 行,位置: 11
  10. 201521123068 《java程序设计》 第13周学习总结
  11. PHP常用功能模块
  12. SpringDay01
  13. springMVC注解总结
  14. C++ 通过ostringstream 实现任意类型转string
  15. python中和生成器协程相关yield from之最详最强解释,一看就懂(二)
  16. Windows 7 64位安装cURL
  17. springboot学习心得
  18. linux minitools+minicom 安装及使用
  19. BZOJ4161 常系数齐次线性递推
  20. dbt 包管理

热门文章

  1. 利用TOAD实现把EXCEL数据导入oracle数据库
  2. [转] 与调试器共舞 - LLDB 的华尔兹
  3. spring web flow 2.0入门(转)
  4. [500lines]500行代码写web server
  5. ORA-00933 UNION 与 ORDER BY
  6. php中的双引号和单引号的区别?
  7. Smarty 模板引擎 fetch()和display()函数的区别?
  8. IE6不完全支持!important
  9. Scut 进阶:Schema 自动检测
  10. KEIL C编译器常见警告与错误信息的解决办法