Git Product home page Git Product logo

array-events's Introduction

array-events.js

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

var EventedArray = require('array-events');
var 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

array-events's People

Contributors

davidcalhoun avatar khrome avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.