Comparing version 3.1.1 to 4.0.0
{ | ||
"name": "vo", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "Vo is a control flow library for minimalists", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
4.0.0 / 2016-06-28 | ||
================== | ||
* add any promise dep | ||
* use a consistent signature for both pipeline and stack | ||
3.1.1 / 2016-03-17 | ||
@@ -3,0 +9,0 @@ ================== |
34
index.js
@@ -7,4 +7,4 @@ 'use strict' | ||
var Promise = global.Promise || require('es6-promise').Promise | ||
var Pipeline = require('./lib/pipeline') | ||
var Promise = require('any-promise') | ||
var Stack = require('./lib/stack') | ||
@@ -30,2 +30,13 @@ var sliced = require('sliced') | ||
function Vo() { | ||
return Vo.pipeline.apply(this, arguments) | ||
} | ||
/** | ||
* Pipeline the functions | ||
* | ||
* @param {Mixed} | ||
* @return {Function} | ||
*/ | ||
Vo.pipeline = function pipeline () { | ||
var pipeline = isArray(this) ? sliced(this) : sliced(arguments) | ||
@@ -43,3 +54,3 @@ | ||
/** | ||
* Pipeline the functions | ||
* Stack the functions (middleware style) | ||
* | ||
@@ -63,2 +74,12 @@ * @param {Mixed} | ||
/** | ||
* Compose the functions | ||
* | ||
* COMING SOON | ||
*/ | ||
Vo.compose = function compose () { | ||
throw new Error('not implemented yet') | ||
} | ||
/** | ||
* Simple wrapper that will allow us | ||
@@ -95,2 +116,11 @@ * to switch between fixed arguments | ||
// thenable support | ||
vo.then = function (success, failure) { | ||
return vo().then(success, failure) | ||
} | ||
vo.catch = function (failure) { | ||
return vo().catch(failure) | ||
} | ||
return vo | ||
@@ -97,0 +127,0 @@ } |
@@ -7,3 +7,4 @@ /** | ||
var error = require('combine-errors') | ||
var wrapped = require('wrapped') | ||
var wrapped = require('./wrap') | ||
let sliced = require('sliced') | ||
var type = require('./type') | ||
@@ -42,6 +43,6 @@ var keys = Object.keys | ||
return function func (args, done) { | ||
wrapped(fn).apply(this, args.concat(next)) | ||
wrapped(fn, next).call(this, args) | ||
function next(err) { | ||
if (err) return done(error(err)) | ||
if (err) return done.apply(null, [err].concat(sliced(arguments))) | ||
return done.apply(null, arguments) | ||
@@ -158,5 +159,7 @@ } | ||
function Catcher(fn) { | ||
return function catcher (err, args, done) { | ||
return wrapped(fn()).apply(this, [err].concat(args).concat(done)) | ||
function catcher (err, args, done) { | ||
return wrapped(fn(), done).call(this, [err].concat(args)) | ||
} | ||
catcher.catch = true | ||
return catcher | ||
} | ||
@@ -163,0 +166,0 @@ |
@@ -24,2 +24,4 @@ /** | ||
pipeline = pipeline.map(compile) | ||
var remaining = args.slice(1) | ||
var al = args.length || 1 | ||
@@ -30,12 +32,14 @@ // run in series | ||
var fn = pipeline.shift() | ||
while (fn && fn.length !== 2) fn = pipeline.shift() | ||
if (!fn) return done.call(context, null, sliced(arguments, 1)) | ||
fn.call(context, sliced(arguments, 1), next) | ||
while (fn && fn.catch === true) fn = pipeline.shift() | ||
var na = sliced(arguments, 1).concat(remaining).slice(0, al) | ||
if (!fn) return done.call(context, null, na) | ||
return fn.call(context, na, next) | ||
} | ||
// error handling | ||
function error (err, args) { | ||
function error (err, ca) { | ||
var fn = pipeline.shift() | ||
while (fn && fn.length !== 3) fn = pipeline.shift() | ||
if (fn) return fn.call(context, err, args, next) | ||
while (fn && fn.catch !== true) fn = pipeline.shift() | ||
var na = ca.concat(remaining).slice(0, al + 1) | ||
if (fn) return fn.call(context, err, na, next) | ||
else return done.call(context, err) | ||
@@ -42,0 +46,0 @@ } |
{ | ||
"name": "vo", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "Vo is a control flow library for minimalists", | ||
@@ -13,11 +13,11 @@ "keywords": [ | ||
], | ||
"author": "Matthew Mueller <matt@lapwinglabs.com>", | ||
"author": "Matthew Mueller <matt@matthewmueller.com>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lapwinglabs/vo.git" | ||
"url": "git://github.com/matthewmueller/vo.git" | ||
}, | ||
"dependencies": { | ||
"combine-errors": "1.0.1", | ||
"es6-promise": "^3.1.2", | ||
"generatorfunction": "0.0.1", | ||
"any-promise": "1.3.0", | ||
"co": "3.1.0", | ||
"combine-errors": "3.0.2", | ||
"lodash.compact": "^3.0.0", | ||
@@ -24,0 +24,0 @@ "sliced": "^1.0.1", |
@@ -6,10 +6,12 @@ | ||
## Features | ||
## What you get | ||
- Seamlessly supports promises, generators, synchronous & asynchronous functions. | ||
- Vo is composable, allowing you to intuitively orchestrate complex work flows | ||
- **new in 4.0** Consistent function signatures | ||
- Tiny library (4kb minified + gzipped) | ||
- Supports promises, generators, & sync functions | ||
- Serial and parallel execution for every flow | ||
- 2 different kinds of flows: pipeline & stack | ||
- Easily catch and fix errors anywhere in the pipeline | ||
- Errors passed as arguments so you know where the failure occurred | ||
- Returns a promise that you can yield on or "await" | ||
- Supports both stack and pipeline task flow | ||
- Tiny (4kb minified + gzip) | ||
- Browser & server support | ||
@@ -25,4 +27,32 @@ - Well-tested | ||
An updated guide will be available soon. For now, take a look at the [tests](test/) for now. | ||
Vo supports 2 kinds of asynchronous flows: | ||
- **pipelines**: Transformation pipeline. Return values become the arguments to the next function | ||
- **stacks**: Express-style. Arguments are passed in at the top and flow through each middleware function | ||
Both of these flows support both parallel and serial execution | ||
## Example | ||
```js | ||
function * get (url) { | ||
return yield fetch(url) | ||
} | ||
function map (responses) { | ||
return responses.map(res => res.status) | ||
} | ||
vo([ | ||
fetch('https://standupjack.com'), | ||
fetch('https://google.com') | ||
], map).then(function (statuses) { | ||
assert.deepEqual([ 200, 200 ]) | ||
}) | ||
``` | ||
## Guide | ||
Coming soon! Check out the comprehensive [test suite](test/) for now. | ||
## Vo Runtime | ||
@@ -43,28 +73,8 @@ | ||
## Things to keep in mind | ||
### FAQ | ||
### Binding a generator function isn't consistently implemented yet | ||
##### Binding a generator function isn't implemented consistently yet | ||
```js | ||
function * a () { | ||
// this === ctx | ||
} | ||
Use [co-bind](https://github.com/vdemedes/co-bind) just to be safe. | ||
vo(a.bind(ctx)) | ||
``` | ||
The following will work on node 5 and latest chrome, but not on latest safari or node 4. Latest babel does not fix this problem. | ||
Just to be safe, I'd install [co-bind](https://github.com/vdemedes/co-bind) and do this instead: | ||
```js | ||
var bind = require('co-bind') | ||
function * a () { | ||
// this === ctx | ||
} | ||
vo(bind(a, ctx)) | ||
``` | ||
## Test | ||
@@ -71,0 +81,0 @@ |
Sorry, the diff of this file is not supported yet
94007
16
2415
89
+ Addedany-promise@1.3.0
+ Addedco@3.1.0
+ Addedany-promise@1.3.0(transitive)
+ Addedcombine-errors@3.0.2(transitive)
+ Addedcustom-error-instance@2.1.1(transitive)
+ Addedlodash._baseiteratee@4.7.0(transitive)
+ Addedlodash._basetostring@4.12.0(transitive)
+ Addedlodash._baseuniq@4.6.0(transitive)
+ Addedlodash._createset@4.0.3(transitive)
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash._stringtopath@4.8.0(transitive)
+ Addedlodash.uniqby@4.5.0(transitive)
- Removedes6-promise@^3.1.2
- Removedgeneratorfunction@0.0.1
- Removedcombine-errors@1.0.1(transitive)
- Removedes6-promise@3.3.1(transitive)
- Removedgeneratorfunction@0.0.1(transitive)
Updatedcombine-errors@3.0.2