0.0.2 • Published 8 years ago

hole-event v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

##hole LICENSE fire in the hole,simple yet event library,dead simple,enjoy it ^_^

Usage

install

~ npm install hole-event

on(eventType, callback)

Register a specific callback to be called when eventType is trigger,return a token,alias bind

hole.on('a.b.c',function(){
    console.log(arguments);
});
hole.fire('a.b.c');
//or 
hole.bind('a.b.c',function(){
   console.log(arguments);
});
var token = hole.on('a.b.c.d',function(){});
token.fire();//token.emit();token.trigger();

once(eventType, callback)

Similar to on but the callback just be invoked once

hole.once('a.b.c.d',function(){
    console.log(arguments);
})
hole.fire('a.b.c',9527);//log
hole.fire('a.b.c',9527);//nothing 

off(eventType)

Remove registered listener by eventType,alias unbind

hole.off('a.b.c')
//or 
hole.unbind('a.b.c')

clear()

Removes all of the registered listeners.

hole.clear();

has(eventType)

If eventType has been registered ,will return true,otherwise return false

hole.has('a.b.c');

emit(eventType,...args)

Emits an event of the given type with the given data,alias firetriggerhole

hole.emit('a.b.c')
//or
hole('a.b.c')
//or
hole.fire('a.b.c')
//or
hole.trigger('a.b.c')

wildcard 通配符

eventType supports wildcard,it is so cool!!

hole.on('a.b.*',function(){

});
hole.fire('a.*');

TODO

test