array-events

2.0.1 • Public • Published

array-events.js

NPM version npm Travis

Is an Array extension class which adds asynchronous functions to Array as well as firing events on 'remove', 'add' or 'change'

import { EventedArray } = from 'array-events/array-events.mjs';
// OR: const EventedArray = require('array-events');
const myArray = new EventedArray();

events

change : fired any time an element is added or removed

add : fired any time an element is added

remove : fired any time an element is removed

emitter functions

EventedArrays are also Emitters but have an expanded syntax from extended-emitter and the additional .when() call.

myArray.on('change', function(event){ });
myArray.once('change', function(event){ });
myArray.off('change', function(event){ });
myArray.emit('change'[, arguments]);

async functions

forEachEmission : execute serially

myArray.forEachEmission(function(item, index, done){
    somethingAsynchronous(function(){
        done();
    });
}, function(){
    //we're all done!
});

forAllEmissions : execute all jobs in parallel

myArray.forAllEmissions(function(item, index, done){
    somethingAsynchronous(function(){
        done();
    });
}, function(){
    //we're all done!
});

forAllEmissionsInPool : execute all jobs in parallel up to a maximum #, then queue for later

myArray.forAllEmissionsInPool(poolSize, function(item, index, done){
    somethingAsynchronous(function(){
        done();
    });
}, function(){
    //we're all done!
});

utility functions

contains : does the array contain this element?

new EventedArray(['dog', 'cat', 'mouse']).contains('cat') //returns true;

combine : generate a new array that is the union of the provided arrays

new EventedArray(['dog', 'cat']).combine(['mouse']) //returns a new array  ['dog', 'cat', 'mouse'];

erase : generate a new array without the member provided

new EventedArray(['dog', 'cat', 'mouse']).erase('cat') //returns a new array ['dog', 'mouse'];

EventedArray.is : is the provided object an instance of EventedArray

EventedArray.is(new EventedArray()); //returns true
EventedArray.is([]) //returns false

Testing

just run

mocha

Enjoy,

-Abbey Hawk Sparrow

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.113latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.113
2.0.00
1.1.00
1.0.00
0.2.07,745
0.1.41
0.1.3-beta0
0.1.1-beta0
0.1.0-beta0
0.0.4-alpha0
0.0.3-alpha0
0.0.2-alpha0
0.0.1-alpha1

Package Sidebar

Install

npm i array-events

Weekly Downloads

7,045

Version

2.0.1

License

MIT

Unpacked Size

30.1 kB

Total Files

10

Last publish

Collaborators

  • khrome