zev-tiny-observable
v0.7.0
Published
tiny observable
Downloads
8
Readme
TinyObservable:
by Jeremy Zevin
Why? Because I wanted to see if I could make a very simple observable that I could use with various projects. Done without looking at anyone elses code.
Install
npm install zev-tiny-observable
Usage
Browser
<script src="https://unpkg.com/zev-tiny-observable/dist/tinyObservable.min.js"></script>
module import
import TinyObservable from 'zev-tiny-observable';
API
Static Contructor Methods
new TinyObservable()
example:
const obs = new TinyObservable();
const sub = obs.subscribe(r => console.log(r));
obs.next('Hi!');
TinyObservable.fromRaf()
example:
const rafObs = new TinyObservable.fromRaf();
const rafSub = rafObs.subscribe(t => console.log(t)) // will receive t from window.requestAnimationFrame
setTimeout(() => rafSub.unsubscribe(), 1000); // will unsubscribe in 1000ms
TinyObservable.fromEvent(eventType, element)
example:
const eventObs = TinyObservable.fromEvent('mousemove', document.body);
const mouseMoveSub = eventObs.subscribe(e => console.log(e));
Subscription.unsubscribe()
example as seen above