Bhiv.js
Bhiv is a utility module which provide a complete syntax to build an asynchronous workflow.
It provides also some basic features like EventEmitter, Object manipulation, or basic functions patterns.
It works on any side
Test:
javascript:(function(s){document.head.appendChild(s);s.src='https://rawgit.com/np42/bhiv/master/Bhiv.js';})(document.createElement('script'));
Install:
<!-- This is not a CDN so don't use it in production -->
npm install --save bhiv
Browser Multi Fetching Exemple
// Assuming jQuery & Bhiv loaded var fetchAllJsonpUrl = { var priv = jQuery: {} console: {} ; var bhiv = priv; privconsole { console; }; privjQuery { var { return ; }; jQuery; }; return // iterating on the direct flow, key is named index, value named url // the following is synchronous, that's why '=' character // requesting and storing the result into the content field // closing the loop (created by the Map keyword, limit parallel execute to 3 tasks) // finishing the workflow build ; }; fetchAllJsonpUrl github: 'https://api.github.com' ip: 'http://jsonip.com' { console; };
Node Module Example
var Bhiv = ; moduleexports = var priv = {}; var bhiv = priv this; thissayHello = ; { this { return 'hello' 'world'; }; this { return word; }; this { return array; }; }; ;
See full syntax documentation into source code at Bee Builder Syntax
Some methods:
* Trap(<pattern>, <work>, <inglue>, <outglue>): do <work> if an error match <pattern>
* Map(<path>, <key>, <value>): iter on <path> and do work for each elements
* -> replace the old list value by result
* Go(<work>, <inglue>, <outglue>): create a une parallel waterfall
* close(<properties>): close task, and set properties
* emit(<event>, <data>): to emit an event (maybe catched by a bucket)
* add(<glue>): allow you to add some thing in the flow
* flatten(): flatten an inherited data structure
* pipe(<work>, <inglue>, <outglue>): execute a task after the previous one if any
* -> replace the result
* then(<work>, <inglue>, <outglue>): execute a task after the previous one if any
* -> merge the result
* waterfall(<tasks>): do all tasks sequencially, with data replacing the previous one
* bucket(<event>, <outglue>, <end>): retrieve data for an <event> even until the <end> event
* extract(<glue>): extract <glue> pattern from data and keep only it
* keep(<fields>): keep only field list
* end(<data>, <callback>): execute the bee or wrap either the <data> or the <callback>