1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-22 22:53:32 +01:00

Fix config.addon bug and augment Class.memoize somewhat.

This commit is contained in:
Kris Maglione
2011-02-14 16:47:57 -05:00
parent 9ef146b93b
commit 0a008b6a51
3 changed files with 40 additions and 26 deletions

View File

@@ -523,9 +523,11 @@ function memoize(obj, key, getter) {
}
return obj;
}
obj.__defineGetter__(key, function g_replaceProperty() (
Class.replaceProperty(this.instance || this, key, null),
Class.replaceProperty(this.instance || this, key, getter.call(this, key))));
obj.__defineSetter__(key, function s_replaceProperty(val)
Class.replaceProperty(this.instance || this, key, val));
}
@@ -765,14 +767,33 @@ Class.extend = function extend(subclass, superclass, overrides) {
* property's value.
* @return {Class.Property}
*/
Class.memoize = function memoize(getter)
Class.memoize = function memoize(getter, wait)
Class.Property({
configurable: true,
enumerable: true,
init: function (key) {
this.get = function replace() let (obj = this.instance || this) (
Class.replaceProperty(obj, key, null),
Class.replaceProperty(obj, key, getter.call(this, key)))
let done = false;
let prop = { configurable: true, enumerable: true, value: null, writable: true };
if (wait)
prop = {
configurable: true, enumerable: false,
get: function get() {
util.waitFor(function () done);
return this[key];
}
}
this.get = function replace() {
let obj = this.instance || this;
Object.defineProperty(obj, key, prop);
try {
return Class.replaceProperty(obj, key, getter.call(this, key));
}
finally {
done = true;
}
}
this.set = function replace(val) Class.replaceProperty(this.instance || this, val);
}
});