This ia an extension module the Mono web framework. The Event module is used by other Mono modules (like the layout module) to add the Mono event support in their configurations.
This module is built only on top of the Mono client library (M.js) and has no further dependencies.
Module that need Mono event support in their configurations need to:
- add this module as a dependency in their
mono.json
descriptor (example):
{
…
"dependencies": [
…
"github/jillix/events/v0.1.1",
…
],
…
}
- require this module in their client scripts (example):
var Events = require('github/jillix/events');
- somewhere in the code (most often seen in the initialization function) call the
Events
function in the scope ofthis
module, passing it the configuration (example):
var Events = require('github/jillix/events');
This module extends a module's configuration with the listen
key.
{
"listen": {
"miid1": {
"event1FromMiid1": [ … ],
"event2FromMiid1": [ … ]
},
"miid2": {
"eventFromMiid2": [ … ]
}
}
}
where:
- listen: is an object that has as keys the
miid
's of the module to listen to and values event objects - event object: is an objectt that has as keys the event names emitted by a module and as values action arrays
- action array: is an array of action objects to take (in order) when the particular event is received
- acction object: has as key one of:
handler
,event
handler
actions can have as value either a string (a function name to be called) or an object if fixed parameters need to be passed to the handler function (see example below)emit
actions have as value a string (an event to be emitted)
{
"listen": {
"miid": {
"eventFromMiid": [
{ "handler": "aFunctionInMiid1" },
{ "handler": { "name": "anotherFunctionInMiid1", "args": ["fixed argument"] } },
{ "emit": "anotherEvent" }
]
}
}
}
- transferred module to the new jxMono organization
- updated Utils to
v0.2.0
- Updated to
[email protected]
- Updated to
[email protected]
- Updated Utils to
v0.1.2
- Added Utils as dependency
- The module can not uninit events (remove handlers) if an extra
true
argument is passed to the library:Events.call(self, self.config, true)
. The module configuration will be changed to store the function handlers.
- Add event even the function is not found when the event is added. The function can be declared latter.
- Fixed broken
hasOwnProperty
that usedreturn
instead ofcontinue
- Fixed counter declaration in for loops: replaced
i
withii
- added
if (!obj.hasOwnProperty(key)) return;
to object for loops
- fixed IE8 compatibility by removing all
for (var i in ...)
expressions - fixed simple event version to support global namespaced functions:
{
"listen": {
"myMiid": {
"myEvent": "simple_handler_call"
}
}
}
- added namespaced function support for handlers
TODO
TODO