async-mixin
caolin/async collection methods as a mixin.
Installation
npm install async-mixin
Usage
Wrap a collection within an object
var asyncMixin = var admins = userIds: 12345 // pass target object + path to the array you want to// enumerate over asynchronouslyvar adminApi = // adminApi has all of the async collection methods:Object // each, eachSeries, eachLimit, map, ...etc // async methods work just like caolin/async's methods,// except they're automatically bound to admins' 'userIds' propertyadminApi
Optionally only include particular async methods
var admins = userIds: 12345 var adminApi = Object // ['map', 'filter'] adminApimap // => [Function]adminApifilter // => [Function]adminApireduce // => undefined
Wrap Arrays directly
var items = 12345 var container = // container now has all of async's methods// bound automatically to the passed-in items:container
Create handy prototype objects
{ thisusers = users} UserCollectionprototype = UserCollectionprototype { // pretend db.save is some async operation that saves users this} UserCollectionprototype { // pretend db.loadProfile is some async operation that loads user profiles this} var users = name: 'Bill' name: 'Bob' users users
Mixin Methods
- concat
- concatSeries
- detect
- detectLimit
- detectSeries
- each
- eachLimit
- eachOf
- eachOfLimit
- eachOfSeries
- eachSeries
- every
- everyLimit
- everySeries
- filter
- filterLimit
- filterSeries
- map
- mapLimit
- mapSeries
- mapValues
- mapValuesLimit
- mapValuesSeries
- reduce
- reduceRight
- reject
- rejectLimit
- rejectSeries
- some
- someLimit
- someSeries
- sortBy
- transform
Safety
async-mixin
does not modify your original object, it simply returns a new
object that inherits from your original object, while adding async methods:
var admins = userIds: 12345 var adminApi = adminApimap // => [Function]adminsmap // => undefined
Inspiration
Similar idea to component/enumerable, but our enumeration methods are asynchronous.
Licence
MIT