зеркало из https://github.com/mozilla/snowl.git
replace Mixin module with Mixins module from jsmodules project
--HG-- extra : rebase_source : b369fd557be1293b5e8f65d638bcd0306899148c
This commit is contained in:
Родитель
248a375e12
Коммит
befa53a70e
|
@ -34,35 +34,52 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
let EXPORTED_SYMBOLS = ["inmix"];
|
||||
let EXPORTED_SYMBOLS = ["Mixins"];
|
||||
|
||||
/**
|
||||
* Inmix attributes (properties, methods, getters/setters) from the source
|
||||
* object into the target object. Doesn't inmix attributes that already exist
|
||||
* in the target object (i.e. doesn't override existing attributes).
|
||||
* Mix attributes (properties, methods, getters/setters) from the source object
|
||||
* into the target object.
|
||||
*
|
||||
* Note: doesn't mix in attributes that already exist in the target object
|
||||
* (i.e. doesn't override existing attributes).
|
||||
* ??? Should it?
|
||||
*
|
||||
* FIXME: give the target object access in some way to the source's version
|
||||
* of attributes it overrides.
|
||||
*
|
||||
* @param target {Object} the object that receives attributes
|
||||
* @param source {Object} the object that provides attributes
|
||||
* @param target {Object} the object that receives attributes
|
||||
*/
|
||||
function inmix(target, source) {
|
||||
for (let attr in source) {
|
||||
// Don't inmix attributes that already exist in the target.
|
||||
if (attr in target)
|
||||
function mixin(source, target) {
|
||||
for (let attribute in source) {
|
||||
// Don't mix in attributes that already exist in the target.
|
||||
if (attribute in target)
|
||||
continue;
|
||||
|
||||
let getter = source.__lookupGetter__(attr);
|
||||
let setter = source.__lookupSetter__(attr);
|
||||
let getter = source.__lookupGetter__(attribute);
|
||||
let setter = source.__lookupSetter__(attribute);
|
||||
|
||||
// We can have a getter, a setter, or both. If we have either, we only
|
||||
// define one or both of them. Otherwise, we assign the property directly.
|
||||
if (getter || setter) {
|
||||
if (getter)
|
||||
target.__defineGetter__(attr, getter);
|
||||
target.__defineGetter__(attribute, getter);
|
||||
if (setter)
|
||||
target.__defineSetter__(attr, setter);
|
||||
target.__defineSetter__(attribute, setter);
|
||||
}
|
||||
else
|
||||
target[attr] = source[attr];
|
||||
target[attribute] = source[attribute];
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: support both source and target arguments accepting arrays of objects.
|
||||
let Mixins = {
|
||||
mix: function(source) {
|
||||
return {
|
||||
source: source,
|
||||
into: function(target) {
|
||||
mixin(this.source, target);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
|
@ -47,7 +47,7 @@ Cu.import("resource://gre/modules/ISO8601DateUtils.jsm");
|
|||
|
||||
// modules that are generic
|
||||
Cu.import("resource://snowl/modules/log4moz.js");
|
||||
Cu.import("resource://snowl/modules/Mixin.js");
|
||||
Cu.import("resource://snowl/modules/Mixins.js");
|
||||
Cu.import("resource://snowl/modules/Observers.js");
|
||||
Cu.import("resource://snowl/modules/Request.js");
|
||||
Cu.import("resource://snowl/modules/URI.js");
|
||||
|
@ -492,5 +492,5 @@ SnowlFeed.prototype = {
|
|||
|
||||
};
|
||||
|
||||
inmix(SnowlFeed.prototype, SnowlSource);
|
||||
Mixins.mix(SnowlSource.prototype).into(SnowlFeed.prototype);
|
||||
SnowlService.addAccountType(SnowlFeed);
|
||||
|
|
|
@ -56,7 +56,10 @@ loader.loadSubScript("chrome://snowl/content/strands.js");
|
|||
|
||||
/**
|
||||
* SnowlSource: a source of messages.
|
||||
*
|
||||
*
|
||||
* FIXME: update this documentation now that we're using it via mixins
|
||||
* instead of inheritance.
|
||||
*
|
||||
* This is an abstract class that should not be instantiated. Rather, objects
|
||||
* should inherit it via one of two methods (depending on whether or not they
|
||||
* also inherit other functionality):
|
||||
|
@ -128,7 +131,8 @@ loader.loadSubScript("chrome://snowl/content/strands.js");
|
|||
* so that subclasses can call the getters directly without causing trouble
|
||||
* for other subclasses that access them via __lookupGetter__.
|
||||
*/
|
||||
let SnowlSource = {
|
||||
function SnowlSource() {}
|
||||
SnowlSource.prototype = {
|
||||
init: function(aID, aName, aMachineURI, aHumanURI, aUsername, aLastRefreshed, aImportance, aPlaceID) {
|
||||
this.id = aID;
|
||||
this.name = aName;
|
||||
|
|
|
@ -46,7 +46,8 @@ const Cu = Components.utils;
|
|||
*
|
||||
* @see SnowlSource.
|
||||
*/
|
||||
let SnowlTarget = {
|
||||
function SnowlTarget() {}
|
||||
SnowlTarget.prototype = {
|
||||
init: function() {},
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ Cu.import("resource://gre/modules/ISO8601DateUtils.jsm");
|
|||
|
||||
// modules that are generic
|
||||
Cu.import("resource://snowl/modules/log4moz.js");
|
||||
Cu.import("resource://snowl/modules/Mixin.js");
|
||||
Cu.import("resource://snowl/modules/Mixins.js");
|
||||
Cu.import("resource://snowl/modules/Observers.js");
|
||||
Cu.import("resource://snowl/modules/URI.js");
|
||||
|
||||
|
@ -749,6 +749,6 @@ SnowlTwitter.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
inmix(SnowlTwitter.prototype, SnowlSource);
|
||||
inmix(SnowlTwitter.prototype, SnowlTarget);
|
||||
Mixins.mix(SnowlSource.prototype).into(SnowlTwitter.prototype);
|
||||
Mixins.mix(SnowlTarget.prototype).into(SnowlTwitter.prototype);
|
||||
SnowlService.addAccountType(SnowlTwitter);
|
||||
|
|
Загрузка…
Ссылка в новой задаче