Class EventProxy
EventProxy. An implementation of task/event based asynchronous pattern.
Defined in: eventproxy.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
EventProxy.
|
| Method Attributes | Method Name and Description |
|---|---|
|
addListener(eventName, callback)
Bind an event, specified by a string name, `ev`, to a `callback` function.
|
|
|
after(eventName, times, callback)
The callback will be executed after the event be fired N times.
|
|
|
all(eventName1, eventName2, callback)
Assign some events, after all events were fired, the callback will be executed once.
|
|
|
any(eventName1, eventName2, callback)
The callback will be executed after any registered event was fired.
|
|
| <static> |
EventProxy.create()
Create a new EventProxy
|
|
immediate(ev, callback, data)
Bind an event, and trigger it immediately.
|
|
|
not(eventName, callback)
The callback will be executed when the evnet name not equals with assigned evnet.
|
|
|
once(ev, callback)
Bind an event like the bind method, but will remove the listener after it was fired.
|
|
|
removeAllListeners(event)
Remove all listeners.
|
|
|
removeListener(eventName, callback)
Remove one or many callbacks.
|
|
|
tail(eventName1, eventName2, callback)
Assign some events, after all events were fired, the callback will be executed first time.
|
|
|
trigger(eventName, data)
Trigger an event, firing all bound callbacks.
|
Class Detail
EventProxy()
EventProxy. A module that can be mixed in to *any object* in order to provide it with
custom events. You may `bind` or `unbind` a callback function to an event;
`trigger`-ing an event fires all callbacks in succession.
var render = function (template, resources) {};
var proxy = new EventProxy();
proxy.assign("template", "l10n", render);
proxy.trigger("template", template);
proxy.trigger("l10n", resources);
Method Detail
addListener(eventName, callback)
Bind an event, specified by a string name, `ev`, to a `callback` function.
Passing `"all"` will bind the callback to all events fired.
- Parameters:
- {string} eventName
- Event name.
- {function} callback
- Callback.
after(eventName, times, callback)
The callback will be executed after the event be fired N times.
- Parameters:
- {string} eventName
- Event name.
- {number} times
- N times.
- {function} callback
- Callback, that will be called after event was fired N times.
all(eventName1, eventName2, callback)
Assign some events, after all events were fired, the callback will be executed once.
proxy.all(ev1, ev2, callback); proxy.all([ev1, ev2], callback); proxy.all(ev1, [ev2, ev3], callback);
- Parameters:
- {string} eventName1
- First event name.
- {string} eventName2
- Second event name.
- {function} callback
- Callback, that will be called after predefined events were fired.
any(eventName1, eventName2, callback)
The callback will be executed after any registered event was fired. It only executed once.
- Parameters:
- {string} eventName1
- Event name.
- {string} eventName2
- Event name.
- {function} callback
- The callback will get a map that has data and eventName attributes.
<static>
{EventProxy}
EventProxy.create()
Create a new EventProxy
var ep = EventProxy.create();
ep.assign('user', 'articles', function(user, articles) {
// do something...
});
// or one line ways: Create EventProxy and Assign
var ep = EventProxy.create('user', 'articles', function(user, articles) {
// do something...
});
- Returns:
- {EventProxy}
immediate(ev, callback, data)
Bind an event, and trigger it immediately.
- Parameters:
- {string} ev
- Event name.
- {function} callback
- Callback.
- {mix} data
- The data that will be passed to calback as arguments.
not(eventName, callback)
The callback will be executed when the evnet name not equals with assigned evnet.
- Parameters:
- {string} eventName
- Event name.
- {function} callback
- Callback.
once(ev, callback)
Bind an event like the bind method, but will remove the listener after it was fired.
- Parameters:
- {string} ev
- Event name.
- {function} callback
- Callback.
removeAllListeners(event)
Remove all listeners.
It equals unbind(); Just add this API for as same as Event.Emitter.
- Parameters:
- {string} event
- Event name.
removeListener(eventName, callback)
Remove one or many callbacks. If `callback` is null, removes all
callbacks for the event. If `ev` is null, removes all bound callbacks
for all events.
- Parameters:
- {string} eventName
- Event name.
- {function} callback
- Callback.
tail(eventName1, eventName2, callback)
Assign some events, after all events were fired, the callback will be executed first time.
then any event that predefined be fired again, the callback will executed with the newest data.
proxy.tail(ev1, ev2, callback); proxy.tail([ev1, ev2], callback); proxy.tail(ev1, [ev2, ev3], callback);
- Parameters:
- {string} eventName1
- First event name.
- {string} eventName2
- Second event name.
- {function} callback
- Callback, that will be called after predefined events were fired.
trigger(eventName, data)
Trigger an event, firing all bound callbacks. Callbacks are passed the
same arguments as `trigger` is, apart from the event name.
Listening for `"all"` passes the true event name as the first argument.
- Parameters:
- {string} eventName
- Event name.
- {mix} data
- Pass in data.