1.0.8 • Published 9 years ago

elephant-ears v1.0.8

Weekly downloads
29
License
-
Repository
github
Last release
9 years ago

elephant-ears

NPM version

Description

Listen to and fire synchronous events.

Installation

npm install elephant-ears

Examples

var Ears = require('elephant-ears');

var ears = new Ears();

var callback = function(arg1, arg2) {
    if (arg1 != null) {
        console.log(arg1);
    }

    if (arg2 != null) {
        console.log(arg2);
    }

    console.log('Event Fired!');
    return ha;
};

ears.on('foo', callback);

var value = ears.trigger('foo');        // Event Fired!
console.log(value);                     // ha

ears.off('foo');

ears.trigger('foo');                    // nothing happens

ears.one('foo', callback);              // event will only fire once

ears.trigger('foo');                    // Event Fired!
ears.trigger('foo');                    // nothing happens

ears.on('foo', callback);
ears.on('bar', callback);

var values = ears.trigger('foo bar');   // Event Fired!
                                        // Event Fired!
console.log(values[0] + value[1]);      // haha

ears.trigger('foo', 'arg1', 'arg2');    // arg1
                                        // arg2
                                        // Event Fired!
                                        
// add a namespace
ears = new Ears('myNameSpace');
ears.on('myNameSpace.change', function() {
    console.log('namespace event fired');
});
ears.trigger('change');                 // namespace event fired
1.0.8

9 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago