1.0.3 • Published 8 years ago

rxjs-small v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Rxjs 精简版 (inspire by Rxjs)

  • 主要用于个人学习

安装


nodejs

  • rxjs-small is available on npm. To install it, type:

    $ npm install rxjs-small

基本使用

Observerable系列 (单路推送)

   'use strict';

   const Observerable = require('rxjs-small').Observerable;

   const observerable = new Observerable((observer) => {
       let initial = 1;
       let id = setInterval(() => {
           observer.next(initial++);
       },1000);
       return () => {
           clearInterval(id);
       }
   });

   observerable.subscribe({
       next: value => console.log(`[value]=[${value}]`)
   });

   setTimeout(function() {
       observerable.unSubscribe();
   }, 5000);

output:

[value]=[1]
[value]=[2]
[value]=[3]
[value]=[4]

Subject系列 (多路推送)

'use strict';

const Subject = require('rxjs-small').Subject;

const subject = new Subject();

subject.subscribe({
  next: (v) => console.log('observerA: ' + v)
});

subject.next(1);
subject.next(2);

subject.subscribe({
  next: (v) => console.log('observerB: ' + v)
});

subject.next(3)

output:

observerA: 1
observerA: 2
observerA: 3
observerB: 3

更多使用参考 demo 目录

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago