compose SnowlTwitter from SnowlSource and SnowlTarget attributes, and factor out composition method (acquire) into Compose module

This commit is contained in:
Myk Melez 2009-03-03 17:12:22 -08:00
Родитель 9c91b11e8c
Коммит 1eac5df561
2 изменённых файлов: 9 добавлений и 96 удалений

Просмотреть файл

@ -46,6 +46,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/ISO8601DateUtils.jsm"); Cu.import("resource://gre/modules/ISO8601DateUtils.jsm");
// modules that are generic // modules that are generic
Cu.import("resource://snowl/modules/Compose.js");
Cu.import("resource://snowl/modules/log4moz.js"); Cu.import("resource://snowl/modules/log4moz.js");
Cu.import("resource://snowl/modules/Observers.js"); Cu.import("resource://snowl/modules/Observers.js");
Cu.import("resource://snowl/modules/URI.js"); Cu.import("resource://snowl/modules/URI.js");
@ -63,6 +64,8 @@ Cu.import("resource://snowl/modules/service.js");
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://snowl/content/strands.js"); loader.loadSubScript("chrome://snowl/content/strands.js");
Object.prototype.acquire = acquire;
/** /**
* Convert a string to an array of character codes. * Convert a string to an array of character codes.
* *
@ -679,36 +682,5 @@ SnowlFeed.prototype = {
}; };
SnowlService.addAccountType(SnowlFeed);
/**
* Acquire attributes (properties, methods, getters/setters) from another
* object. Doesn't acquire attributes that already exist in the acquiring
* object (i.e. that have been overridden by that object).
*
* FIXME: give the acquiring object access to the attributes it overrides.
*
* @param obj {Object} the object from which to acquire attributes
*/
Object.prototype.acquire = function(obj) {
for (let attr in obj) {
// Don't acquire attributes we have overridden.
if (attr in this)
continue;
let getter = obj.__lookupGetter__(attr);
let setter = obj.__lookupSetter__(attr);
if (getter || setter) {
if (getter)
this.__defineGetter__(attr, getter);
if (setter)
this.__defineSetter__(attr, setter);
}
else
this[attr] = obj[attr];
}
}
SnowlFeed.prototype.acquire(SnowlSource); SnowlFeed.prototype.acquire(SnowlSource);
SnowlService.addAccountType(SnowlFeed);

Просмотреть файл

@ -46,6 +46,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/ISO8601DateUtils.jsm"); Cu.import("resource://gre/modules/ISO8601DateUtils.jsm");
// modules that are generic // modules that are generic
Cu.import("resource://snowl/modules/Compose.js");
Cu.import("resource://snowl/modules/log4moz.js"); Cu.import("resource://snowl/modules/log4moz.js");
Cu.import("resource://snowl/modules/Observers.js"); Cu.import("resource://snowl/modules/Observers.js");
Cu.import("resource://snowl/modules/URI.js"); Cu.import("resource://snowl/modules/URI.js");
@ -64,6 +65,8 @@ Cu.import("resource://snowl/modules/service.js");
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript("chrome://snowl/content/strands.js"); loader.loadSubScript("chrome://snowl/content/strands.js");
Object.prototype.acquire = acquire;
const TYPE = "SnowlTwitter"; const TYPE = "SnowlTwitter";
const NAME = "Twitter"; const NAME = "Twitter";
const MACHINE_URI = URI.get("https://twitter.com"); const MACHINE_URI = URI.get("https://twitter.com");
@ -152,70 +155,7 @@ SnowlTwitter.prototype = {
refreshInterval: 1000 * 60 * 3, // 3 minutes refreshInterval: 1000 * 60 * 3, // 3 minutes
id: null,
// FIXME: remove "type", as it is no longer being used (we use the constructor
// instead to identify what type of source this is).
type: null,
name: null,
machineURI: null,
get principal() {
return SnowlSource.__lookupGetter__("principal").call(this);
},
humanURI: null,
username: null,
_lastRefreshed: null,
get lastRefreshed() {
return SnowlSource.__lookupGetter__("lastRefreshed").call(this);
},
set lastRefreshed(newValue) {
return SnowlSource.__lookupSetter__("lastRefreshed").call(this, newValue);
},
importance: null,
placeID: null,
get faviconSvc() {
return SnowlSource.faviconSvc;
},
get faviconURI() {
return SnowlSource.__lookupGetter__("faviconURI").call(this);
},
// refresh is defined elsewhere. // refresh is defined elsewhere.
//refresh: function(refreshTime) {},
persist: function() {
SnowlSource.persist.call(this);
},
get _stmtGetInternalIDForExternalID() {
return SnowlSource._stmtGetInternalIDForExternalID;
},
_getInternalIDForExternalID: function(externalID) {
return SnowlSource._getInternalIDForExternalID.call(this, externalID);
},
get _stmtInsertPart() {
return SnowlSource._stmtInsertPart;
},
get _stmtInsertPartText() {
return SnowlSource._stmtInsertPartText;
},
addPart: function(messageID, content, mediaType, partType, baseURI, languageTag) {
return SnowlSource.addPart.call(this, messageID, content, mediaType, partType, baseURI, languageTag);
},
//**************************************************************************// //**************************************************************************//
// SnowlTarget // SnowlTarget
@ -223,7 +163,6 @@ SnowlTwitter.prototype = {
maxMessageLength: 140, maxMessageLength: 140,
// send is defined elsewhere. // send is defined elsewhere.
//send: function() {},
//**************************************************************************// //**************************************************************************//
@ -865,4 +804,6 @@ SnowlTwitter.prototype = {
} }
}; };
SnowlTwitter.prototype.acquire(SnowlSource);
SnowlTwitter.prototype.acquire(SnowlTarget);
SnowlService.addAccountType(SnowlTwitter); SnowlService.addAccountType(SnowlTwitter);