Comparing version 3.0.4 to 3.1.0
16
index.js
@@ -428,2 +428,8 @@ var abbott = require('abbott'); | ||
if(!reducer){ | ||
reducer = function(previous, next){ | ||
return righto(next); | ||
}; | ||
} | ||
return righto.from(values).get(function(values){ | ||
@@ -445,11 +451,3 @@ if(!values || !values.reduce){ | ||
return values.reduce(function(previous, next){ | ||
if(reducer){ | ||
return righto(function(previous, done){ | ||
reducer(previous, next)(done); | ||
}, previous); | ||
} | ||
return righto(function(done){ | ||
return next(done); | ||
}, righto.after(righto.from(previous))); | ||
return righto.sync(reducer, previous, righto.value(next)); | ||
}, seed); | ||
@@ -456,0 +454,0 @@ }); |
{ | ||
"name": "righto", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
# Righto | ||
Wana do some async stuff? Righto.. | ||
An Eventuals implementation that: | ||
- Lets you use synchronous functions, err-backs (normal callback style), promises, iterators (yield), whatever you like. | ||
- Are lazily evaluated. | ||
- Implicitly (and transparently) handles execution order and parallelisation. | ||
- Provides a solution for all common (and some less common) async flows, parallel, waterfall, series, etc, etc... | ||
- Doesn't catch thrown errors. [Why is this good?](https://github.com/korynunn/righto-v-promise#errors) | ||
# What | ||
`righto` takes a task to run, and arguments to pass to the task. If you pass any eventual arguments (rightos or promises), they will be resolved before running the dependant task. | ||
make caching, dependency resolving tasks | ||
`righto` takes a task to run, and arguments to pass to the task. If you pass a `righto`'d task as an argument, it will be resolved before running the dependant task. | ||
```javascript | ||
righto(task, [argument or righto task]) | ||
``` | ||
**`righto`'d tasks are resolved once** and the result is cached. If a task is in flight when it's results are asked for, the results will be passed when the task resolves. | ||
## Who's using it? | ||
<img src="https://s.yimg.com/ao/i/mp/properties/multipass/img/plus7/channel-logo-seven.png" alt="7Tennis" height="70px"/> Used in the backend of https://7tennis.com.au/, which handled 800k concurrent users for the early 2017 season. | ||
<img src="https://securetenant.com.au/images/st-logo4.svg" alt="Secure tenent" height="70px"/> Used everywhere in the backend and frontend of https://securetenant.com.au/ | ||
## example: | ||
async dependencies passed to bar: | ||
```javascript | ||
// Make a task from an err-back function | ||
var document = righto(db.Documents.get, documentId); | ||
// Just your average callback-passing-style function. | ||
function foo(callback){ | ||
var user = righto(db.Users.get, userId); | ||
setTimeout(function(){ | ||
// Resolve an object with eventual properties to pass to a function. | ||
var account = righto(db.Accounts.get, righto.resolve({ | ||
userId: user.get('id') | ||
})); | ||
callback(null, 'world'); | ||
// Reject the flow if a business rule is not met | ||
function isOwner(document, account){ | ||
if(document.ownerId !== account.id){ | ||
return righto.fail({ message: 'Account does not own document', code: 403 }); | ||
} | ||
} | ||
}, 1000); | ||
// Make a task from a synchronous function | ||
// Depend on `document` and `account` in parallel, automatically. | ||
var hasPermission = righto.sync(isOwner, document, account); | ||
} | ||
// Take results from a task only after another task is complete | ||
var allowedDocument = righto.mate(document, righto.after(hasPermission)); | ||
// A righto callback-passing-style function | ||
var getFoo = righto(foo); | ||
// Use the results. | ||
allowedDocument(function(eror, document){ | ||
// Respond with the error or the document. | ||
}); | ||
``` | ||
// Another normal callback-passing-style function. | ||
function bar(a, callback){ | ||
callback(null, 'hello ' + a); | ||
} | ||
## Who's using it? | ||
// Another righto | ||
var getBar = righto(bar, getFoo); | ||
<img src="https://s.yimg.com/ao/i/mp/properties/multipass/img/plus7/channel-logo-seven.png" alt="7Tennis" height="70px"/> Used in the backend of https://7tennis.com.au/, which handled 800k concurrent users for the early 2017 season. | ||
getBar(function(error, result){ | ||
## Usage: | ||
// ...about 1 second later... | ||
result -> 'hello world'; | ||
}); | ||
```javascript | ||
var eventual = righto(task, any...); | ||
``` | ||
@@ -163,3 +159,3 @@ | ||
``` | ||
```javascript | ||
// Lazily resolve (won't run untill called) | ||
@@ -183,3 +179,3 @@ var something = righto(getSomething); | ||
``` | ||
```javascript | ||
// Immediately force the righto to begin resolving. | ||
@@ -521,15 +517,2 @@ var something = righto(getSomething)(); // <= note the call with no arguments. | ||
## Possible rightos: righto.from(anything) | ||
Any value can be turned into a righto using righto.from(); | ||
```javascript | ||
var num = righto.from(1); // -> righto:number; | ||
var string = righto.from('hello'); // -> righto:string; | ||
var nothing = righto.from(null); // -> righto:null; | ||
var anyValue = righto.from(anything); // -> righto:anything; | ||
var self = righto.from(someRighto); // -> someRighto; | ||
``` | ||
## Resolve | ||
@@ -536,0 +519,0 @@ |
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
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
68869
1782
723