Comparing version 0.1.3 to 0.1.5
@@ -1,2 +0,2 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n.flume=n.flume||{})}(this,function(n){"use strict";function e(n,e){return e={exports:{}},n(e,e.exports),e.exports}function t(n){return function(e,t,r){return[null,n(t,r)]}}function r(n,e){function t(n,t,r){try{var u=e(n,t,r);return[u,u]}catch(i){console.log(i)}}return arguments.length<2&&(e=n,n=o),e=u(e),{init:n,process:t}}function u(n){if("function"==typeof n)return n;if(Array.isArray(n))return i(n);throw Error("Unsupported reducer type given to reduce(): "+typeof n)}function i(n){var e=f;return"function"==typeof n[n.length-1]&&(e=n[n.length-1],n=n.slice(0,-1)),function(t,r,u){for(var i,o=u.source,f=-1,c=n.length;++f<c;)if(i=n[f],i[0]===o)return i[1](t,r,u);return e(t,r,u)}}function o(){return null}function f(n,e){return e}function c(n){return n}function s(n){return n=n||c,function(e,t,r){return[null,E([n(t,r),t]).then(l)]}}function l(n){return n[0]?n[1]:A}function p(n,e){function t(n,t,r){return[n,e(n,t,r)]}return{init:n,process:t}}function a(){return""}function h(n){function e(e,t){var r=(e+t).split(n);return[r.slice(-1),r.slice(0,-1)]}return{init:a,process:e}}var d="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},y=e(function(n,e){!function(n,t){"function"==typeof n.define&&n.define.amd?n.define(t):"object"==typeof e?t(!0):n.flume=t()}(d,function(e){function t(){return new c}function r(n){function e(n,e,r){var u=m(t.inputs,n),i=u.length,o=-1;for(r=_(i,r||x);++o<i;)u[o].handle(e,r);return t}var t={};return t.dispatch=e,t.inputs=p(t,n),t}function u(n,e){return new f(n,e)}function i(n){return o({"flume:error":n})}function o(n){return{process:w({"*":d},n)}}function f(n,e){this.type=n,this.value=e}function c(){this.defType="input"}function s(n){this.defType="processor",this.init=A(n.init,x),this.process=n.process}function l(n,e,t,r){this.graph=n,this.def=e,this.child=t,this.index=r,this.handle=y(this)}function p(n,e,t,r){var u=e.length-1;if(u<0)return[];for(u&&(t=new l(n,h(e[u]),t,r));--u>0;)t=new l(n,h(e[u]),t,0);return a(n,e[0],t)}function a(n,e,t){e=q(e);for(var r,u=[],i=-1,o=e.length;++i<o;)if(r=e[i],Array.isArray(r))u.push.apply(u,p(n,r,t,i));else{if(!(r instanceof c))throw Error("Expected input or array but got "+S(r));u.push(new l(n,r,t,i))}return u}function h(n){if("function"==typeof n)n={process:{"flume:value":n}};else if("function"==typeof(n||0).process)n=w(n,{process:{"flume:value":n.process}});else if("object"!==S((n||0).process))throw Error("Expected function or object matching processor shape but got "+S(n));return new s(n)}function d(n,e){return[e]}function y(n){return{input:v,processor:g}[n.def.defType](n)}function v(n){return function(e,t){n.child.handle(e,n,n,t)}}function g(n){function e(n){s.push(n),l||t()}function t(){p=s.shift(),p&&r()}function r(){return l=!0,h().then(k).then(f,c)}function i(){var e=n.def.process,t=e[p.msg.type]||e["*"];return t?t(a,p.msg.value,{source:p.source.def,parent:p.parent.def,dispatch:n.graph.dispatch}):[a,p.msg]}function o(e){var r=p;l=!1,p=null,n.child?n.child.handle(e,n,r.source,r.end):r.end(),t()}function f(n){var e;Array.isArray(n)?(a=n[0],e=n.length>1?n[1]:a):e=C,o(e)}function c(e){if(!n.child)throw new z(e);o(u("flume:error",e))}var s=[],l=!1,p=null,a=n.def.init(),h=T(i);return function(n,t,r,u){n=q(n).map(E);for(var i=-1,o=n.length-1,f={source:r,parent:t};++i<o;)e(w(f,{msg:n[i],end:x}));o>-1&&e(w(f,{msg:n[o],end:u}))}}function m(n,e){for(var t,r=[],u=n.length,i=-1;++i<u;)t=n[i],t.def===e&&r.push(t);return r}function w(){for(var n,e={},t=Array.prototype.slice.call(arguments),r=-1,u=t.length;++r<u;){n=t[r];for(var i in n)n.hasOwnProperty(i)&&(e[i]=n[i])}return e}function x(){return null}function A(n,e){return void 0===n?e:n}function b(n){return n}function j(n){throw n}function E(n){return n instanceof f?n:u("flume:value",n)}function q(n){return Array.isArray(n)?n:[n]}function S(n){return null!==n?typeof n:"null"}function _(n,e){var t=0;return function(){++t>=n&&e.apply(null,arguments)}}function T(n){return function(){try{var e=n.apply(this,arguments);return F(e)}catch(t){if(t instanceof z)throw t.error;return P(t)}}}function F(n){return U(n)?n:O(n)}function O(n){return new B(n,(!1))}function P(n){return new B(n,(!0))}function k(n){return Array.isArray(n)&&n.filter(U).length>0?M(n):F(n)}function M(n){function e(){return F(n[++f]).then(t)}function t(n){u.push(n)}function r(){return u}for(var u=[],i=n.length,o=-1,f=-1,c=O(null);++o<i;)c=c.then(e);return c.then(r)}function U(n){return!!(n||0).then}function z(n){this.error=n}function B(n,e){this.value=n,this.isFailure=e}var C=u("flume:nil",null);return B.prototype.then=T(function(n,e){return this.isFailure?(e||j).call(this,this.value):(n||b).call(this,this.value)}),e?void(n.exports={create:r,input:t,message:u,trap:o,except:i,nil:C,conj:w,maybeAsync:T,resolveSeq:k}):{create:r,input:t,message:u,trap:o,except:i,nil:C,conj:w,maybeAsync:T,resolveSeq:k}})}),v=y.create,g=y.input,m=y.message,w=y.trap,x=y.except,A=y.nil,b=y.conj,j=y.maybeAsync,E=y.resolveSeq;n.map=t,n.reduce=r,n.filter=s,n.sink=p,n.strsplit=h,n.__moduleExports=y,n.create=v,n.input=g,n.message=m,n.trap=w,n.except=x,n.nil=A,n.conj=b,n.maybeAsync=j,n.resolveSeq=E,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.flume=n.flume||{})}(this,function(n){"use strict";function t(n,t){return t={exports:{}},n(t,t.exports),t.exports}function e(n){return{value:n}}function r(n){return n=P(n),function(t,r,u){return n(r,u).then(e)}}function u(n){return{state:n}}function i(n,t){function e(n,e,r){return t(n,e,r).then(u)}return arguments.length<2&&(t=n,n=c),t=P(o(t)),{init:n,transform:e}}function o(n){if("function"==typeof n)return n;if(Array.isArray(n))return f(n);throw Error("Unsupported reducer type given to reduce(): "+typeof n)}function f(n){var t=a;return"function"==typeof n[n.length-1]&&(t=n[n.length-1],n=n.slice(0,-1)),function(e,r,u){for(var i,o=u.source,f=-1,c=n.length;++f<c;)if(i=n[f],i[0]===o)return i[1](e,r,u);return t(e,r,u)}}function c(){return null}function a(n,t){return t}function s(n){return n}function l(n){return n=n||s,function(t,r,u){return q([n(r,u),r]).then(p).then(e)}}function p(n){return n[0]?n[1]:E}function h(n,t){function r(n,r,u){return t(n,r,u).then(e)}return t=P(t),{init:n,transform:r}}function d(){return""}function y(n){function t(t,e){var r=(t+e).split(n);return{state:r.slice(-1),values:r.slice(0,-1)}}return{init:d,transform:t}}function v(n,t){function e(n,t){var e={};for(var u in n)n.hasOwnProperty(u)&&(e[u]=r(n[u],t));return e}function r(n,t){return function(e){t(n,e)}}return arguments.length<2&&(t=n,n=O),function(r,u,i){return r=r||e(t,i.dispatch),{state:r,value:n(u,r)}}}var m="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g=t(function(n,t){!function(n,e){"function"==typeof n.define&&n.define.amd?n.define(e):"object"==typeof t?e(!0):n.flume=e()}(m,function(t){function e(){return new c}function r(n){function t(n,t,r){var u=g(e.inputs,n),i=u.length,o=-1;for(r=S(i,r||b);++o<i;)u[o].handle(t,r);return e}var e={};return e.dispatch=t,e.inputs=l(e,n),e}function u(n,t){return new f(n,t)}function i(n){return o({"flume:error":n})}function o(n){return{transform:w({"*":d},n)}}function f(n,t){this.type=n,this.value=t}function c(){this.defType="input"}function a(n){this.defType="transform",this.init=x(n.init,b),this.transform=n.transform}function s(n,t,e,r){this.graph=n,this.def=t,this.child=e,this.index=r,this.handle=y(this)}function l(n,t,e,r){var u=t.length-1;if(u<0)return[];for(u&&(e=new s(n,h(t[u]),e,r));--u>0;)e=new s(n,h(t[u]),e,0);return p(n,t[0],e)}function p(n,t,e){t=P(t);for(var r,u=[],i=-1,o=t.length;++i<o;)if(r=t[i],Array.isArray(r))u.push.apply(u,l(n,r,e,i));else{if(!(r instanceof c))throw Error("Expected input or array but got "+q(r));u.push(new s(n,r,e,i))}return u}function h(n){if("function"==typeof n)n={transform:{"flume:value":n}};else if("function"==typeof(n||0).transform)n=w(n,{transform:{"flume:value":n.transform}});else if("object"!==q((n||0).transform))throw Error("Expected function or object matching transform shape but got "+q(n));return new a(n)}function d(n,t){return{state:t}}function y(n){return{input:v,transform:m}[n.def.defType](n)}function v(n){return function(t,e){n.child.handle([t],n,n,e)}}function m(n){function t(n){a.push(n),s||e()}function e(){l=a.shift(),l&&r()}function r(){return s=!0,h().then(I).then(f,c)}function i(){var t=n.def.transform,e=t[l.msg.type]||t["*"];return e?e(p,l.msg.value,{source:l.source.def,parent:l.parent.def,dispatch:n.graph.dispatch}):{value:l.msg}}function o(t){var r=l;s=!1,l=null,n.child?n.child.handle(t,n,r.source,r.end):r.end(),e()}function f(n){n=O(p,n),p=n.state,o(n.values)}function c(t){if(!n.child)throw new z(t);o([u("flume:error",t)])}var a=[],s=!1,l=null,p=n.def.init(),h=T(i);return function(n,e,r,u){n=n.map(E);for(var i=-1,o=n.length-1,f={source:r,parent:e};++i<o;)t(w(f,{msg:n[i],end:b}));o>-1&&t(w(f,{msg:n[o],end:u}))}}function g(n,t){for(var e,r=[],u=n.length,i=-1;++i<u;)e=n[i],e.def===t&&r.push(e);return r}function w(){for(var n,t={},e=Array.prototype.slice.call(arguments),r=-1,u=e.length;++r<u;){n=e[r];for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i])}return t}function b(){return null}function x(n,t){return void 0===n?t:n}function A(n){return n}function j(n){throw n}function E(n){return n instanceof f?n:u("flume:value",n)}function O(n,t){var e,r=t.hasOwnProperty("state");return t.hasOwnProperty("value")?e=[t.value]:t.hasOwnProperty("values")?e=t.values:r&&(e=[t.state]),{values:e,state:r?t.state:n}}function P(n){return Array.isArray(n)?n:[n]}function q(n){return null!==n?typeof n:"null"}function S(n,t){var e=0;return function(){++e>=n&&t.apply(null,arguments)}}function T(n){return function(){try{var t=n.apply(this,arguments);return _(t)}catch(e){if(e instanceof z)throw e.error;return k(e)}}}function _(n){return U(n)?n:F(n)}function F(n){return new B(n,(!1))}function k(n){return new B(n,(!0))}function I(n){return Array.isArray(n)&&n.filter(U).length>0?M(n):_(n)}function M(n){function t(){return _(n[++f]).then(e)}function e(n){u.push(n)}function r(){return u}for(var u=[],i=n.length,o=-1,f=-1,c=F(null);++o<i;)c=c.then(t);return c.then(r)}function U(n){return!!(n||0).then}function z(n){this.error=n}function B(n,t){this.value=n,this.isFailure=t}var C=u("flume:nil",null);return B.prototype.then=T(function(n,t){return this.isFailure?(t||j).call(this,this.value):(n||A).call(this,this.value)}),t?void(n.exports={create:r,input:e,message:u,trap:o,except:i,nil:C,conj:w,maybeAsync:T,resolveSeq:I}):{create:r,input:e,message:u,trap:o,except:i,nil:C,conj:w,maybeAsync:T,castThenable:_,resolveSeq:I}})}),w=g.create,b=g.input,x=g.message,A=g.trap,j=g.except,E=g.nil,O=g.conj,P=g.maybeAsync,q=g.resolveSeq;n.map=r,n.reduce=i,n.filter=l,n.sink=h,n.strsplit=y,n.bindInputs=v,n.__moduleExports=g,n.create=w,n.input=b,n.message=x,n.trap=A,n.except=j,n.nil=E,n.conj=O,n.maybeAsync=P,n.resolveSeq=q,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=flume.min.js.map |
11
index.js
@@ -1,1 +0,10 @@ | ||
export * from './src'; | ||
var core = require('./core') | ||
module.exports = core.conj(core, { | ||
map: require('./map'), | ||
reduce: require('./reduce'), | ||
filter: require('./filter'), | ||
sink: require('./sink'), | ||
strsplit: require('./strsplit'), | ||
bindInputs: require('./bindInputs') | ||
}) |
{ | ||
"name": "flume-js", | ||
"version": "0.1.3", | ||
"description": "define event-prone applications as a tree of functions", | ||
"version": "0.1.5", | ||
"description": "a library for defining applications as a set of inputs and transformations", | ||
"license": "MIT", | ||
"repository": "justinvdm/flume", | ||
"main": "dist/flume.min.js", | ||
"jsnext:main": "src/index.js", | ||
"main": "./index.js", | ||
"type": "commonjs", | ||
"exports": { | ||
"import": "./index.mjs", | ||
"require": "./index.js" | ||
}, | ||
"author": { | ||
@@ -13,43 +17,40 @@ "name": "justinvdm" | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"test": "ava tests/*.test.js", | ||
"lint": "eslint index.js tests/*.js", | ||
"check": "npm run lint && npm test", | ||
"clean": "rm -rf dist", | ||
"bundle:prd": "NODE_ENV=production rollup -cmo dist/flume.min.js", | ||
"build": "npm run clean && mkdir dist && npm run bundle:prd", | ||
"preversion": "npm run check", | ||
"version": "npm run build && git add -A dist", | ||
"postversion": "git push && git push --tags" | ||
"build": "otr build", | ||
"lint": "otr lint", | ||
"format": "otr format", | ||
"test": "otr test", | ||
"release": "otr release", | ||
"checks": "yarn lint && yarn test" | ||
}, | ||
"files": [ | ||
"*.js", | ||
"utils/*.js", | ||
"*.mjs", | ||
"dist" | ||
], | ||
"keywords": [ | ||
"dataflow", | ||
"frp", | ||
"functional", | ||
"reactive", | ||
"frp", | ||
"flux" | ||
"programming" | ||
], | ||
"dependencies": { | ||
"flume-core": "~0.1.3" | ||
"oftherivier": { | ||
"type": "es5", | ||
"src": "index.js" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.15.2", | ||
"babel": "^6.5.2", | ||
"babel-eslint": "^7.0.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.16.0", | ||
"eslint": "^3.7.1", | ||
"rollup": "^0.36.3", | ||
"rollup-plugin-commonjs": "^5.0.5", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"rollup-plugin-uglify": "^1.0.1" | ||
"renovate": { | ||
"extends": [ | ||
"github>oftherivier/tools" | ||
] | ||
}, | ||
"ava": { | ||
"require": "babel-register" | ||
"babel": true | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
"transform-es2015-modules-commonjs" | ||
] | ||
"devDependencies": { | ||
"@oftherivier/tools": "0.1.38" | ||
} | ||
} |
227
readme.md
@@ -1,73 +0,62 @@ | ||
# flume-js | ||
# `flume` | ||
[![Build Status](https://travis-ci.org/justinvdm/flume-core.svg?branch=master)](https://travis-ci.org/justinvdm/flume) | ||
> define event-prone applications as a tree of functions | ||
> a library for defining applications as a set of inputs and transformations | ||
**note** flume is more of an experiment at this point, don't use in it production and expect the api to change drastically. The current documentation also leaves much to be desired. If this experiment sees some success, better documentation on what flume is and how it can be used can be expected. | ||
**note** flume is more of an experiment at this point, don't use in it | ||
production and expect the api to change. The current documentation also leaves | ||
much to be desired. If this experiment sees some success, better documentation | ||
on what flume is and how it can be used can be expected. | ||
```js | ||
import {create, input, map, reduce} from 'flume-js'; | ||
import { create, input, map, reduce } from 'flume-js' | ||
const src1 = input(); | ||
const src2 = input(); | ||
const src1 = input() | ||
const src2 = input() | ||
const a = [src1] | ||
.concat(map(v => v * 2)); | ||
const a = [src1].concat(map(v => v * 2)) | ||
const b = [src2] | ||
.concat(map(v => v * 3)); | ||
const b = [src2].concat(map(v => v * 3)) | ||
const graph = [[a, b]] | ||
.concat(reduce(() => 1, (total, v) => total + v)) | ||
.concat(map(console.log)); | ||
.concat( | ||
reduce( | ||
() => 1, | ||
(total, v) => total + v | ||
) | ||
) | ||
.concat(map(console.log)) | ||
create(graph) | ||
.dispatch(src1, 1) // 3 | ||
.dispatch(src2, 2) // 9 | ||
.dispatch(src1, 3); // 15 | ||
.dispatch(src1, 1) // 3 | ||
.dispatch(src2, 2) // 9 | ||
.dispatch(src1, 3) // 15 | ||
``` | ||
## install | ||
``` | ||
$ npm i -S flume-js | ||
``` | ||
## usage | ||
At the moment, flume can be used in with es2015-module-aware bundlers and commonjs environments: | ||
```js | ||
// example using commonjs | ||
const flume = require('flume-js'); | ||
// example using es2015-aware bundlers | ||
import {create, input, map, reduce} from 'flume-js'; | ||
``` | ||
## overview | ||
### what is flume? | ||
flume is an attempt at a library for defining your applications as a set of inputs and transformations of those inputs. | ||
To some limited degree, it is along the same lines as [Observables](https://github.com/tc39/proposal-observable) and libraries like [rxjs](https://github.com/ReactiveX/rxjs) and [xstream](http://staltz.com/xstream/). | ||
flume is a library for defining your applications as a set of inputs and | ||
transformations of those inputs. | ||
To some limited degree, it is along the same lines as | ||
[Observables](https://github.com/tc39/proposal-observable) and libraries like | ||
[rxjs](https://github.com/ReactiveX/rxjs) and | ||
[xstream](http://staltz.com/xstream/). | ||
### api overview | ||
Applications can be thought of as pipelines. In the simplest case, we can have a single input at the top, followed by transform functions: | ||
Applications can be thought of as pipelines. In the simplest case, we can have a | ||
single input at the top, followed by transform functions: | ||
```js | ||
const src = input(); | ||
const src = input() | ||
const app = create([ | ||
src, | ||
map(v => v * 2), | ||
map(v => v + 1), | ||
map(console.log) | ||
]); | ||
const app = create([src, map(v => v * 2), map(v => v + 1), map(console.log)]) | ||
app | ||
.dispatch(src, 2) // 5 | ||
.dispatch(src, 3) // 7 | ||
.dispatch(src, 2) // 5 | ||
.dispatch(src, 3) // 7 | ||
``` | ||
@@ -78,4 +67,4 @@ | ||
```js | ||
const src1 = input(); | ||
const src2 = input(); | ||
const src1 = input() | ||
const src2 = input() | ||
@@ -87,7 +76,7 @@ const app = create([ | ||
map(console.log) | ||
]); | ||
]) | ||
app | ||
.dispatch(src1, 2) // 5 | ||
.dispatch(src2, 3) // 7 | ||
.dispatch(src1, 2) // 5 | ||
.dispatch(src2, 3) // 7 | ||
``` | ||
@@ -98,10 +87,16 @@ | ||
```js | ||
import {create, input, map, reduce} from 'flume-js'; | ||
import { create, input, map, reduce } from 'flume-js' | ||
const src1 = input(); | ||
const src2 = input(); | ||
const src1 = input() | ||
const src2 = input() | ||
const app = create([ | ||
[[src1, map(v => v * 2)], [src2, map(v => v * 3)]], | ||
reduce(() => 1, (total, v) => total + v), | ||
[ | ||
[src1, map(v => v * 2)], | ||
[src2, map(v => v * 3)] | ||
], | ||
reduce( | ||
() => 1, | ||
(total, v) => total + v | ||
), | ||
map(console.log) | ||
@@ -111,23 +106,17 @@ ]) | ||
app | ||
.dispatch(src1, 1) // 3 | ||
.dispatch(src2, 2) // 9 | ||
.dispatch(src1, 3); // 15 | ||
.dispatch(src1, 1) // 3 | ||
.dispatch(src2, 2) // 9 | ||
.dispatch(src1, 3) // 15 | ||
``` | ||
**note** The examples above use array literals to define the application. While this helps for demonstration purposes, the indended convention for defining applications is to use [`Array.prototype.concat()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/concat). This allows us to define applications using a chainable api without flume needing to create some wrapper api to achieve the same result. More importantly though, since `Array.prototype.concat` accepts arrays of values, this also gives us a pattern for appending multiple transforms. For example: | ||
```js | ||
const flatMap = fn => [] | ||
.concat(flatten()) | ||
.concat(map(fn)); | ||
const flatMap = fn => [].concat(flatten()).concat(map(fn)) | ||
const src = input(); | ||
const src = input() | ||
const graph = [input] | ||
.concat(flatMap(v => v * 2)) | ||
.concat(map(console.log)); | ||
const graph = [input].concat(flatMap(v => v * 2)).concat(map(console.log)) | ||
create(graph) | ||
.dispatch(src, 2) | ||
// 4 | ||
// 4 | ||
.dispatch(src, [3, 4]) | ||
@@ -143,6 +132,10 @@ // 6 | ||
### main design goals | ||
- constrain applications to statically defined graph of inputs and transforms | ||
- support defining of message types (e.g. values, errors, types of side effects, custom) | ||
- transforms return results instead of pushing them through in an imperitive manner | ||
- support promise-returning functions, but don't mandate promise support for apps that don't need it | ||
- support defining of message types (e.g. values, errors, types of side effects, | ||
custom) | ||
- transforms return results instead of pushing them through in an imperitive | ||
manner | ||
- support promise-returning functions, but don't mandate promise support for | ||
apps that don't need it | ||
@@ -157,12 +150,14 @@ ## api | ||
Graphs are defined as arrays. The first element of the array may be an [`input`](#input), a graph definition, or an array of either of these. All following array elements may only be a [transform](#transforms) (see [transform definitions](#transform-definitions) for a lower-level api for defining these). | ||
Graphs are defined as arrays. The first element of the array may be an | ||
[`input`](#input), a graph definition, or an array of either of these. All | ||
following array elements may only be a [transform](#transforms) (see | ||
[transform definitions](#transform-definitions) for a lower-level api for | ||
defining these). | ||
```js | ||
const src = input(); | ||
const src = input() | ||
const app = [src] | ||
.concat(map(console.log)); | ||
const app = [src].concat(map(console.log)) | ||
create(app) | ||
.dispatch(src, 23); // 23 | ||
create(app).dispatch(src, 23) // 23 | ||
``` | ||
@@ -190,9 +185,16 @@ | ||
In the simplest case, a transform can be defined as a function. A transform function takes in the transform's current `state`, the `value` to be transformed, and an `opts` object. It should return an object containing with the folling properties: | ||
In the simplest case, a transform can be defined as a function. A transform | ||
function takes in the transform's current `state`, the `value` to be | ||
transformed, and an `opts` object. It should return an object containing with | ||
the folling properties: | ||
- `state`: the transform's new state. If omitted, the node's current state is assumed. | ||
- `value` / `values`: the result value to propagated to the next transform in the chain. If specified using the property name `values`, the property is taken as an [array of result values](#propagating-multiple-values) to be propagated sequentially. | ||
- `state`: the transform's new state. If omitted, the node's current state is | ||
assumed. | ||
- `value` / `values`: the result value to propagated to the next transform in | ||
the chain. If specified using the property name `values`, the property is | ||
taken as an [array of result values](#propagating-multiple-values) to be | ||
propagated sequentially. | ||
```js | ||
const src = input(); | ||
const src = input() | ||
@@ -203,22 +205,23 @@ const graph = [src] | ||
value: (state || 0) + v + 1 | ||
}) | ||
.concat(map(console.log)); | ||
})) | ||
.concat(map(console.log)) | ||
create(graph) | ||
.dispatch(src, 1) // 2 | ||
.dispatch(src, 2); // 4 | ||
.dispatch(src, 1) // 2 | ||
.dispatch(src, 2) // 4 | ||
``` | ||
If `value`/`values` are omitted but `state` is given, `state` is used as both the transform's new state _and_ the result value to be propagated. | ||
If `value`/`values` are omitted but `state` is given, `state` is used as both | ||
the transform's new state _and_ the result value to be propagated. | ||
```js | ||
const src = input(); | ||
const src = input() | ||
const graph = [src] | ||
.concat((state, v) => ({state: (state || 0) + v})) | ||
.concat(map(console.log)); | ||
.concat((state, v) => ({ state: (state || 0) + v })) | ||
.concat(map(console.log)) | ||
create(graph) | ||
.dispatch(src, 2) // 2 | ||
.dispatch(src, 3); // 5 | ||
.dispatch(src, 2) // 2 | ||
.dispatch(src, 3) // 5 | ||
``` | ||
@@ -229,3 +232,4 @@ | ||
- `source`: the input from which propagation started | ||
- `parent`: the definition of the transform or input from which `value` propagated | ||
- `parent`: the definition of the transform or input from which `value` | ||
propagated | ||
- `dispatch`: a reference to [`graph.dispatch()`](#graph-dispatch-src-value). | ||
@@ -248,1 +252,40 @@ | ||
#### `conj(...objects)` | ||
## install | ||
You can use this library as the npm package `flume-js`: | ||
``` | ||
npm i flume-js | ||
# or | ||
yarn add flume-js | ||
``` | ||
It can be used in both es-module-aware and commonjs bundlers/environments. | ||
```js | ||
// es module | ||
import { create } from 'flume-js' | ||
// or alternatively | ||
import create from 'flume-js/create' | ||
// commonjs | ||
const { create } = require('flume-js') | ||
// or alternatively | ||
const create = require('flume-js/create') | ||
``` | ||
It can also be used a `<script>`: | ||
```html | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/pipe-with/dist/umd/flume.js" | ||
></script> | ||
<script> | ||
flume.create(...) | ||
</script> | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
80834
0
1
528
282
1
23
1
- Removedflume-core@~0.1.3
- Removedflume-core@0.1.3(transitive)