flaxa

1.1.0 • Public • Published

Flaxa: event functions

Subscribe to function events

npm version

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

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

 
const flaxa = require('flaxa')
 
const addOverTime = flaxa(
  // flaxa emit function
  (emit) => 
  // your function
  (a, b) => {  
    let i = 0
    const interval = setInterval(() => {
 
      if(=== 5){
        clearInterval(interval)
        // emit to all subscribers
        // if you emit finally no other emits will work after 
        emit('finally', (+ b) + i)
      }
      // emit to all subscribers
      emit('update', (+ 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)
 

Readme

Keywords

Package Sidebar

Install

npm i flaxa

Weekly Downloads

0

Version

1.1.0

License

ISC

Last publish

Collaborators

  • richie_south