mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 16:32:27 +01:00
Fix config.addon bug and augment Class.memoize somewhat.
This commit is contained in:
@@ -255,24 +255,16 @@ var CommandWidgets = Class("CommandWidgets", {
|
|||||||
commandbar: Class.memoize(function () ({ group: "Cmd" })),
|
commandbar: Class.memoize(function () ({ group: "Cmd" })),
|
||||||
statusbar: Class.memoize(function () ({ group: "Status" })),
|
statusbar: Class.memoize(function () ({ group: "Status" })),
|
||||||
|
|
||||||
_whenReady: function _whenReady(name, id, processor) {
|
_whenReady: function _whenReady(name, id) {
|
||||||
Object.defineProperty(this, name, {
|
|
||||||
configurable: true, enumerable: true,
|
|
||||||
get: function get_whenReady() {
|
|
||||||
let elem = document.getElementById(id);
|
let elem = document.getElementById(id);
|
||||||
|
|
||||||
util.waitFor(function () elem.contentDocument.documentURI === elem.getAttribute("src") &&
|
util.waitFor(function () elem.contentDocument.documentURI === elem.getAttribute("src") &&
|
||||||
["viewable", "complete"].indexOf(elem.contentDocument.readyState) >= 0);
|
["viewable", "complete"].indexOf(elem.contentDocument.readyState) >= 0);
|
||||||
|
|
||||||
res = res || (processor || util.identity).call(self, elem);
|
return elem;
|
||||||
return res;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let res, self = this;
|
|
||||||
return Class.replaceProperty(this, name, this[name]);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get completionList() this._whenReady("completionList", "dactyl-completions"),
|
completionList: Class.memoize(function () this._whenReady("completionList", "dactyl-completions"), true),
|
||||||
|
|
||||||
completionContainer: Class.memoize(function () this.completionList.parentNode),
|
completionContainer: Class.memoize(function () this.completionList.parentNode),
|
||||||
|
|
||||||
@@ -286,13 +278,13 @@ var CommandWidgets = Class("CommandWidgets", {
|
|||||||
return document.getElementById("dactyl-contextmenu");
|
return document.getElementById("dactyl-contextmenu");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
get multilineOutput() this._whenReady("multilineOutput", "dactyl-multiline-output",
|
multilineOutput: Class.memoize(function () {
|
||||||
function (elem) {
|
let elem = this._whenReady("multilineOutput", "dactyl-multiline-output");
|
||||||
elem.contentWindow.addEventListener("unload", function (event) { event.preventDefault(); }, true);
|
elem.contentWindow.addEventListener("unload", function (event) { event.preventDefault(); }, true);
|
||||||
elem.contentDocument.documentElement.id = "dactyl-multiline-output-top";
|
elem.contentDocument.documentElement.id = "dactyl-multiline-output-top";
|
||||||
elem.contentDocument.body.id = "dactyl-multiline-output-content";
|
elem.contentDocument.body.id = "dactyl-multiline-output-content";
|
||||||
return elem;
|
return elem;
|
||||||
}),
|
}, true),
|
||||||
|
|
||||||
multilineInput: Class.memoize(function () document.getElementById("dactyl-multiline-input")),
|
multilineInput: Class.memoize(function () document.getElementById("dactyl-multiline-input")),
|
||||||
|
|
||||||
@@ -576,9 +568,10 @@ var CommandLine = Module("commandline", {
|
|||||||
|
|
||||||
get completionList() {
|
get completionList() {
|
||||||
let node = this.widgets.active.commandline;
|
let node = this.widgets.active.commandline;
|
||||||
if (!node.completionList)
|
if (!node.completionList) {
|
||||||
this.widgets._whenReady.call(node, "completionList", "dactyl-completions-" + node.id,
|
let elem = this.widgets._whenReady("completionList", "dactyl-completions-" + node.id);
|
||||||
function (node) ItemList(node.id));
|
node.completionList = ItemList(elem.id);
|
||||||
|
}
|
||||||
return node.completionList;
|
return node.completionList;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -523,9 +523,11 @@ function memoize(obj, key, getter) {
|
|||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.__defineGetter__(key, function g_replaceProperty() (
|
obj.__defineGetter__(key, function g_replaceProperty() (
|
||||||
Class.replaceProperty(this.instance || this, key, null),
|
Class.replaceProperty(this.instance || this, key, null),
|
||||||
Class.replaceProperty(this.instance || this, key, getter.call(this, key))));
|
Class.replaceProperty(this.instance || this, key, getter.call(this, key))));
|
||||||
|
|
||||||
obj.__defineSetter__(key, function s_replaceProperty(val)
|
obj.__defineSetter__(key, function s_replaceProperty(val)
|
||||||
Class.replaceProperty(this.instance || this, key, val));
|
Class.replaceProperty(this.instance || this, key, val));
|
||||||
}
|
}
|
||||||
@@ -765,14 +767,33 @@ Class.extend = function extend(subclass, superclass, overrides) {
|
|||||||
* property's value.
|
* property's value.
|
||||||
* @return {Class.Property}
|
* @return {Class.Property}
|
||||||
*/
|
*/
|
||||||
Class.memoize = function memoize(getter)
|
Class.memoize = function memoize(getter, wait)
|
||||||
Class.Property({
|
Class.Property({
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
init: function (key) {
|
init: function (key) {
|
||||||
this.get = function replace() let (obj = this.instance || this) (
|
let done = false;
|
||||||
Class.replaceProperty(obj, key, null),
|
let prop = { configurable: true, enumerable: true, value: null, writable: true };
|
||||||
Class.replaceProperty(obj, key, getter.call(this, key)))
|
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);
|
this.set = function replace(val) Class.replaceProperty(this.instance || this, val);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
if (addon && !addon.getResourceURI)
|
if (addon && !addon.getResourceURI)
|
||||||
util.reportError(Error("Don't have add-on yet"));
|
util.reportError(Error("Don't have add-on yet"));
|
||||||
|
|
||||||
return !addon || addon.getResourceURI();
|
return !addon || addon.getResourceURI;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!addon)
|
if (!addon)
|
||||||
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
||||||
return addon;
|
return addon;
|
||||||
}),
|
}, true),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current application locale.
|
* The current application locale.
|
||||||
|
|||||||
Reference in New Issue
Block a user