What have the EventEmitter framework ever done for us?

Wed 31 August 2011

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:

    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":
      function(stuff) {
        worker.postMessage(new Message(msg.data.backMessage,

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) {
     function(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?

Category: computer Tagged: jetpack firefox bugTriage