blob: 6548d00b977f029a4b2dc6c2c35b64f1fa6db014 (
plain) (
tree)
|
|
What have the EventEmitter framework ever done for us?
######################################################
:date: 2011-08-31T14:08:10
:category: computer
:tags: jetpack, firefox, bugTriage
So, I was one of the people behind `the bug request`_ which lead to `the
EventEmitter framework`_.
So, when I have now a moment I was looking at my scripts how to make to
use it. The situation before was that I had this ``pageMod`` creator::
pageMod.PageMod({
include : interestingURLsArray,
contentScriptWhen : 'ready',
contentScriptFile : contentScriptLibraries,
onAttach : function onAttach(worker, msg) {
worker.on('message', function(msg) {
messageHandler(worker, msg);
});
});
and ``messageHandler`` handler was just one very ugly
``switch(msg.cmd)`` which contained sections like::
case "GetURL":
libbz.getURL(msg.data.url,
function(stuff) {
worker.postMessage(new Message(msg.data.backMessage,
stuff));
});
break;
Not nice but useable. All the ugly switching logic was hidden behind the
corner and it was obvious what it does. Now with the advent of
``EventEmitter`` framework I should change my pageMod’s ``onAttach``
handler to contain endless list of very ugly spaghetti calls like::
worker.port.on('GetURL', function (command) {
libbz.getURL(command.url,
function(stuff) {
worker.port.emit(command.backMessage,
stuff);
});
});
What is the advantage? `What have the EventEmitter framework ever done
for us?`_ I am not sure I know what is the answer,
I guess we could improve the situation a bit if page.PageMod creator was
actually returning an instance variable and event handlers could be
hooked on it (in the similar pattern as the ``Widget``\ ’s on the
instance variable. Why it isn't possible to do so with PageMod?
.. _`the bug request`:
https://bugzilla.mozilla.org/show_bug.cgi?id=635748
.. _`the EventEmitter framework`:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/api-utils/docs/events.html
.. _`What have the EventEmitter framework ever done for us?`:
https://youtu.be/Qc7HmhrgTuQ
|