micro-observable
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

micro-observable

RxJS6-style observables in less than 1kb, with code taken from RxJS, toy-rx and more.

Build Status Version

Setup

npm install -D micro-observable

Use

import { Observable, map, filter } from 'micro-observable';
 
let myObs = Observable.create(observer => { // Create an observable
  let x = 0;
  let y = setInterval(() => {
    observer.next(x++); // that emits incrementing values
  }, 1000); // each second
  return function cleanup() {
    clearInterval(y); // and cleans up after its self
  }
}).pipe(
  map(x => x * x), // square each member
  filter(x => x % 3 === 0) // keep only those that are multiples of 3
);
 
let s = myObs.subscribe(x => {
  console.log(x);
});
 
setTimeout(() => {
  s.unsubscribe(); // unsubscribe
}, 10000); // after 10s

Is this equivalent to RxJS?

Absolutely not. There are tons of edge and corner cases that this library doesn't aim to handle. micro-observable is great for simple producers and consumers, where a full-blown FRP library would be overkill.


(c) 2018

Readme

Keywords

Package Sidebar

Install

npm i micro-observable

Weekly Downloads

2

Version

1.3.0

License

MIT

Unpacked Size

1.21 MB

Total Files

87

Last publish

Collaborators

  • northm