Ee
Event-Driven library inspired by the EventEmitter.
Install
npm install ee
API
Ee
new Ee([Event])
Event
defaults to Ee.Event
var ee = ;
ee.Event === Ee.Event
is true
or
var { EeEvent;}; CustomEventprototype = Object;CustomEventprototype { return 'nyan!';}; var ee = CustomEvent;
and
ee;
ee.Event === CustomEvent
is true
ee.on(event, listener, [times], [until], [first]) -> ee
Adds a listener to the end of the listeners for the specified event.
event
: string or array of string, event to listen. (required)listener
: function or array of function, listener. (required)times
: number, times to be executed. (optional)first
: boolean, add a listener to the beginning of the listeners. (optional)until
: string or array of string, listener will be removed when this event is executed. (optional)
ee.first(event, listener, [times], [until]) -> ee
Adds a listener to the beginning of the listeners for the specified event.
ee.once(event, listener, [until], [first]) -> ee
Adds a one time listener to the end of the listeners for the specified event.
ee.until(until, event, listener, [times], [first]) -> ee
Adds a listener will be removed when specified event is executed.
ee.until_once(until, event, listener, [first]) -> ee
Equals ee.until(until, event, listener, 1, [first])
ee.until_mutually(events, listener, [until], [times], [first])
ee.until_mutually(options)
ee;
is equal to
var {}; ee ;
options
is Object has keys
events
: array of string, event to listen and to remove. (required)listener
: function or array of function, listener. (required)until
: string or array of string, listener will be removed when this event is executed. (optional)times
: number, times to be executed. (optional)first
: boolean, add a listener to the beginning of the listeners. (optional)
ee.until_once_mutually(events, listener, [until], [first])
ee.until_once_mutually(options)
Equals ee.until_mutually(events, listener, [until], 1, [first])
ee.within(within, event, listener, [callback], [times], [until], [first]) -> ee
ee.within(options) -> ee
Adds a listener will be removed when specified time is reached.
options
is Object has keys
within
: number, milliseconds. (required)event
: string or array of string, event to listen. (required)listener
: function or array of function, listener. (required)callback
: function, called when specified time is reached. (optional)times
: number, times to be executed. (optional)first
: boolean, add a listener to the beginning of the listeners. (optional)until
: string or array of string, listener will be removed when this event is executed. (optional)
ee.within_once(within, event, listener, [callback], [until], [first]) -> ee
ee.within_once(options) -> ee
Equals ee.within(within, event, listener, [callback], 1, [until], [first])
ee; ee;
then
ee;
first nyan
on nyan!
once nyan?
until neko nyan
within 1000ms nyan
ee;
first nyan
on nyan!
until neko nyan
within 1000ms nyan
ee;
true
ee;
first nyan
on nyan!
within 1000ms nyan
;
first nyan
on nyan!
ee.off(event, [listener]) -> ee
Remove a listener or all listeners for the specified event.
event
: string or array of string, event to remove listener. (required)listener
: function or array of function, listener to be removed. (optional)
ee.size([event]) -> Number
Returns the number of listeners for the specified event or all listeners.
ee.ever([event]) -> Number
Returns number of executions for the specified event or for all events.
ee.listeners([event]) -> Array
Returns an array of listeners for the specified event.
ee.emit(event, [argument1], [argument2], [...]) -> ee
Execute each of the listeners in order with the supplied arguments.
ee; ee;
nyan!
nyan?
undefined
Otherwise,
ee;
ee.chain(event, [arguments], [complete], [hook]) -> ee
ee.chain(event, [complete], [hook]) -> ee
Execute each of the listeners.
ee;
then
ee; console;
current listener expects 4 arguments
nyan!
nyan?
undefined
◡( ╹◡╹ )◡
current listener expects 2 arguments
nyan!
complete!
or
ee; console;
current listener expects 4 arguments
◡( ╹◡╹ )◡
nyan!
nyan?
undefined
current listener expects 2 arguments
nyan!
complete!
application
ee; ee;
complete!
ee.parallel(event, [arguments], [complete], [hook]) -> ee
ee.parallel(event, [complete], [hook]) -> ee
Execute each of the listeners.
ee; ee;
listener 1
listener 2
listener 3
ee.reserve(event) -> ee
Reserve specified event.
ee.unreserve(event) -> ee
Cancel reservation of specified event.
ee.lookup([pattern], [callback]) -> Array
ee.lookup(pattern, callback, [return_self]) -> Array | ee
ee.lookup(callback, [return_self]) -> Array | ee
Lookup events match to the specified pattern.
when return_self
is true
, then return ee
.
ee ; console;
[ 'reserved', 'not reserved' ]
ee ; console;
[ 'reserved' ]
Ee.Event
new Ee.Event(event)
Create a new instance.
e.abort() -> e
Set e.aborted
to true
and skip other listeners.
ee; ee;
first listener.
e.prevent() -> e
Set e.prevented
to true
and skip other listeners.
ee; ee;
e.stop() -> e
Set e.aborted
and e.prevented
to true
and skip other listeners.
e.next() -> e
Execute next listener.
e.get(key, [default_value]) -> mixed
Get value or default_value
.
e.set(key, value) -> e
Set value for key.
e.unset(key) -> e
Unset key.
Ee.DataStore (Utility)
var object = ; object; console;
ko!
or
var object = {}; EeDataStore; object; console;
ko!
e.get(key, [default_value]) -> mixed
Get value or default_value
.
e.set(key, value) -> e
Set value for key.
e.unset(key) -> e
Licence
The MIT License (MIT)
Copyright (c) 2013 tatあt ioiioioloo@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.