https://github.com/wuz/pazaak
A functional observable library for JS
https://github.com/wuz/pazaak
Last synced: 3 months ago
JSON representation
A functional observable library for JS
- Host: GitHub
- URL: https://github.com/wuz/pazaak
- Owner: wuz
- Archived: true
- Created: 2017-03-13T20:07:19.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T17:35:08.000Z (over 2 years ago)
- Last Synced: 2025-03-02T23:35:07.966Z (3 months ago)
- Language: JavaScript
- Size: 204 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Pazaak
======
[](https://coveralls.io/github/ohmfox/pazaak)[](https://travis-ci.org/ohmfox/pazaak)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`