summaryrefslogtreecommitdiffstats
path: root/computer/what-have-the-eventemitter-framework-ever-done-for-us.rst
diff options
context:
space:
mode:
Diffstat (limited to 'computer/what-have-the-eventemitter-framework-ever-done-for-us.rst')
-rw-r--r--computer/what-have-the-eventemitter-framework-ever-done-for-us.rst61
1 files changed, 61 insertions, 0 deletions
diff --git a/computer/what-have-the-eventemitter-framework-ever-done-for-us.rst b/computer/what-have-the-eventemitter-framework-ever-done-for-us.rst
new file mode 100644
index 0000000..a7ba4a0
--- /dev/null
+++ b/computer/what-have-the-eventemitter-framework-ever-done-for-us.rst
@@ -0,0 +1,61 @@
+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?`:
+ http://www.youtube.com/watch?v=ExWfh6sGyso