callbag-from-function

2.1.0 • Public • Published

callbag-from-function

Generate a Callbag from a function. Whenever the function is called, the source will emit what the function returned.

npm install callbag-from-function

usage

const {source, emitter} = fromFunction(someFunc);

Now, whenever you call emitter with some ...args, source will emit what someFunc returns when called with ...args.

The emitter will also return the emitted value.

If no function is passed in, an identity function will be used.

The source is "hot" (using callbag-share), meaning it can take many listeners.

example

Wrapping an action creator in an app with a state stream.

const forEach = require('callbag-for-each');
const fromFunction = require('callbag-from-function');
 
const newName = str => ({type: 'NEWNAME', value: str});
 
const {source: newName$, emitter: wrappedNewName} = fromFunction(newName);
 
const forEach(newName$)(a => console.log("New name:", a.value));
 
wrappedNewName("Batman"); // New name: Batman

Readme

Keywords

Package Sidebar

Install

npm i callbag-from-function

Weekly Downloads

10

Version

2.1.0

License

MIT

Unpacked Size

5.39 kB

Total Files

6

Last publish

Collaborators

  • krawaller