Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/richie-south/flaxa
Flaxa: event functions
https://github.com/richie-south/flaxa
events npm thing
Last synced: about 5 hours ago
JSON representation
Flaxa: event functions
- Host: GitHub
- URL: https://github.com/richie-south/flaxa
- Owner: richie-south
- Created: 2017-03-01T23:04:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-10T12:26:11.000Z (over 7 years ago)
- Last Synced: 2024-11-13T00:03:20.703Z (4 days ago)
- Topics: events, npm, thing
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flaxa: event functions
Subscribe to function events[![npm version](https://badge.fury.io/js/flaxa.svg)](https://badge.fury.io/js/flaxa)
`npm install flaxa --save`
**Use flaxa to subscribe to events on your function.**
**Input function can be a promise or async to be more powerful.**
Example
```javascript
const flaxa = require('flaxa')const addOverTime = flaxa(
// emit fn from flaxa
(emit) =>
// your function that should do stuff...
(a) => {
// emit to all subscribers
emit('my emit value', a)
return a
}
)// your subscriptions
addOverTime.on('my emit value', (value) => {
console.log(value) // hello world
})// run your function
addOverTime('hello world') // hello world```
Example
```javascriptconst flaxa = require('flaxa')
const addOverTime = flaxa(
// flaxa emit function
(emit) =>
// your function
(a, b) => {
let i = 0
const interval = setInterval(() => {if(i === 5){
clearInterval(interval)
// emit to all subscribers
// if you emit finally no other emits will work after
emit('finally', (a + b) + i)
}
// emit to all subscribers
emit('update', (a + b) + i)i++
}, 500)return a + b
})// your subscriptions
addOverTime.on('update', (files) => {
console.log('folderDone:', files)
})addOverTime.on('finally', (value) => {
console.log('finally:', value)
})// run your function
addOverTime(1, 1)```