Skip to content

wuz/pazaak

Repository files navigation

Pazaak

Coverage Status

Build Status

A functional observable library.

Installation

npm install pazaak

Usage

var pazaak = require('pazaak').pazaak;

// Create a new observable
function myObservable() {
 //Return a function that takes a function
 return pazaak(observer => {
   try {
      var handler = ({ pageX, pageY }) => {
         //Observe a change
         observer.next({ x: pageX, y: pageY });
      }
      //Listen to browser mouse moves
      document.addEventListener('mousemove', handler);

      // Call complete after 10 seconds
      setTimeout(() => {
         observer.complete();
         document.removeEventListener('mousemove', handler);
      }, 10000);

      // Returns a destroy function
      return () => {
         document.removeEventListener('mousemove', handler);
      };
   } catch (e) {
      //Handle any errors
      observer.error(e);
   }
 });
}

// Subscribe to the observable (subs has an unsubscribe method to stop listening)
const subs = myObservable().subscribe({
  next({x, y}) {
    console.log(x, y);
  },
  error(e) {
    console.log(e);
  },
  complete() {
    console.log('done');
  }
});

Tests

More tests need written - see contributing section.

npm test

Contributing

Be sure to test and lint.

npm run lint

About

A functional observable library for JS

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published