From 3d3cef1a6fe9878a5dbd93dc0156180d86862587 Mon Sep 17 00:00:00 2001 From: Joe Walker Date: Tue, 23 Nov 2010 15:38:32 +0000 Subject: [PATCH] make canon and settings use EventEmitter --- plugins/pilot/lib/canon.js | 18 ++++++++---------- plugins/pilot/lib/settings.js | 19 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/plugins/pilot/lib/canon.js b/plugins/pilot/lib/canon.js index d9fd2b57..ce822a6b 100644 --- a/plugins/pilot/lib/canon.js +++ b/plugins/pilot/lib/canon.js @@ -39,7 +39,7 @@ define(function(require, exports, module) { var console = require('pilot/console'); var Trace = require('pilot/stacktrace').Trace; -//var Event = require('events').Event; +var MEventEmitter = require("pilot/event_emitter").MEventEmitter; exports.startup = function(data, reason) { if (!data.env || !data.env.settings) { @@ -91,7 +91,7 @@ exports.Canon.prototype = { } }; -// exports.addedRequestOutput = new Event(); +oop.implement(exports, MEventEmitter); /** * Current requirements are around displaying the command line, and provision @@ -130,7 +130,7 @@ exports.addRequestOutput = function(request) { exports.requests.shiftObject(); } - exports.addedRequestOutput(request); + exports.$dispatchEvent('addedRequestOutput', { request: request }); }; /** @@ -189,10 +189,10 @@ exports.Request = function(options) { this.end = null; this.completed = false; this.error = false; - -// this.changed = new Event(); }; +oop.implement(exports.Request.prototype, MEventEmitter); + /** * Lazy init to register with the history should only be done on output. * init() is expensive, and won't be used in the majority of cases @@ -238,7 +238,7 @@ exports.Request.prototype.output = function(content) { } this.outputs.push(content); - this.changed(); + this.$dispatchEvent('changed', {}); return this; }; @@ -254,11 +254,9 @@ exports.Request.prototype.done = function(content) { if (content) { this.output(content); - } else { - this.changed(); } + + this.$dispatchEvent('changed', {}); }; - - }); diff --git a/plugins/pilot/lib/settings.js b/plugins/pilot/lib/settings.js index 9f6af921..94f8bcbd 100644 --- a/plugins/pilot/lib/settings.js +++ b/plugins/pilot/lib/settings.js @@ -43,9 +43,10 @@ define(function(require, exports, module) { -var console = require("util/console"); -var types = require("types"); -var Event = require("events").Event; +var console = require("pilot/console"); +var oop = require("pilot/oop").oop; +var types = require("pilot/types"); +var MEventEmitter = require("pilot/event_emitter").MEventEmitter; exports.startup = function(data, reason) { // TODO add extension point in new style @@ -141,12 +142,6 @@ function Settings(persister) { if (persister) { this.setPersister(persister); } - - /** - * Event that tells people when a setting has changed. - */ - // TODO: Fix events - // this.settingChange = new Event({ keyElement: 0 }); }; Settings.prototype = { @@ -235,9 +230,7 @@ Settings.prototype = { persister.persistValue(this, key, value); } - // Inform subscriptions of the change - // TODO: fix events - // this.settingChange(key, converted); + this.$dispatchEvent('settingChange', { key: key, value: value }); return this; }, @@ -318,6 +311,8 @@ Settings.prototype = { } }; +oop.implement(Settings.prototype, MEventEmitter); + exports.settings = new Settings(new MemoryPersister()); /**