-
Notifications
You must be signed in to change notification settings - Fork 2
Extend bouton with your operator and source
Bo HOU edited this page Jul 8, 2016
·
2 revisions
Bouton.js provides a basic set of operators and sources. You can easily extend it with your operators/sources.
Operator and source are just functions, who returns a Node instance.
operator signature in flowtype:
function operator(...args) => Nodesource signature in flowtype:
function source(...args) => NodeYou can add a new operator to bouton:
const bouton = require("bouton")
.addDefault(); // optional, add default operators and sources
// add your operator
bouton.addOperator("testOperator", yourOperator);
// use it in a stream
bouton.asList([1, 2, 3])
.testOperator(...) // pass any argument to your operatorSource is added to bouton as a top level function by addSource
const bouton = require("bouton")
.addDefault(); // optional, add default operators and sources
// add your source
bouton.addSource("anotherSource", yourOperator);
// use it in a stream
bouton.anotherSource
.act(console.log) // pass any argument to your operatorYou can organise your operators in a node module, which exports its operators as a key:value pair. Then you can use addOperators() function to add them to bouton.
There exits a similar function *addSources() for adding multiple sources.
const bouton = require("bouton");
const ops = require("you operator module");
const srcs = require("your source module");
bouton
.addOperators(ops)
.addSources(srcs);
bouton.yourSource(...)
.yourOps(...)