1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-31 09:22:27 +01:00

Flush all caches on :rehash.

This commit is contained in:
Kris Maglione
2011-09-30 19:40:20 -04:00
parent e8f99427d1
commit 625c3cef8b
4 changed files with 68 additions and 47 deletions

View File

@@ -123,22 +123,17 @@ update(CommandOption, {
var Command = Class("Command", {
init: function init(specs, description, action, extraInfo) {
specs = Array.concat(specs); // XXX
let parsedSpecs = extraInfo.parsedSpecs || Command.parseSpecs(specs);
this.specs = specs;
this.shortNames = array.compact(parsedSpecs.map(function (n) n[1]));
this.longNames = parsedSpecs.map(function (n) n[0]);
this.name = this.longNames[0];
this.names = array.flatten(parsedSpecs);
this.description = description;
this.action = action;
if (extraInfo.options)
this._options = extraInfo.options;
delete extraInfo.options;
if (extraInfo)
this.update(extraInfo);
if (this.options)
this.options = this.options.map(CommandOption.fromArray, CommandOption);
for each (let option in this.options)
option.localeName = ["command", this.name, option.names[0]];
},
get toStringParams() [this.name, this.hive.name],
@@ -220,17 +215,21 @@ var Command = Class("Command", {
* @property {[string]} All of this command's name specs. e.g., "com[mand]"
*/
specs: null,
parsedSpecs: Class.Memoize(function () Command.parseSpecs(this.specs)),
/** @property {[string]} All of this command's short names, e.g., "com" */
shortNames: null,
shortNames: Class.Memoize(function () array.compact(this.parsedSpecs.map(function (n) n[1]))),
/**
* @property {[string]} All of this command's long names, e.g., "command"
*/
longNames: null,
longNames: Class.Memoize(function () this.parsedSpecs.map(function (n) n[0])),
/** @property {string} The command's canonical name. */
name: null,
name: Class.Memoize(function () this.longNames[0]),
/** @property {[string]} All of this command's long and short names. */
names: null,
names: Class.Memoize(function () this.names = array.flatten(this.parsedSpecs)),
/** @property {string} This command's description, as shown in :listcommands */
description: Messages.Localized(""),
@@ -283,7 +282,13 @@ var Command = Class("Command", {
* @property {Array} The options this command takes.
* @see Commands@parseArguments
*/
options: [],
options: Class.Memoize(function ()
this._options.map(function (opt) {
let option = CommandOption.fromArray(opt);
option.localeName = ["command", this.name, option.names[0]];
return option;
}, this)),
_options: [],
optionMap: Class.Memoize(function () array(this.options)
.map(function (opt) opt.names.map(function (name) [name, opt]))

View File

@@ -46,35 +46,13 @@ var Option = Class("Option", {
init: function init(modules, names, description, defaultValue, extraInfo) {
this.modules = modules;
this.name = names[0];
this.names = names;
this.realNames = names;
this.description = description;
if (extraInfo)
this.update(extraInfo);
if (Set.has(this.modules.config.optionDefaults, this.name))
defaultValue = this.modules.config.optionDefaults[this.name];
if (defaultValue == null && this.getter)
defaultValue = this.getter();
if (defaultValue !== undefined) {
if (this.type === "string")
defaultValue = Commands.quote(defaultValue);
if (isObject(defaultValue))
defaultValue = iter(defaultValue).map(function (val) val.map(Option.quote).join(":")).join(",");
if (isArray(defaultValue))
defaultValue = defaultValue.map(Option.quote).join(",");
this.defaultValue = this.parse(defaultValue);
}
// add no{option} variant of boolean {option} to this.names
if (this.type == "boolean")
this.names = array([name, "no" + name] for (name in values(names))).flatten().array;
this._defaultValue = defaultValue;
if (this.globalValue == undefined && !this.initialValue)
this.globalValue = this.defaultValue;
@@ -103,8 +81,15 @@ var Option = Class("Option", {
},
/** @property {value} The option's global value. @see #scope */
get globalValue() { try { return options.store.get(this.name, {}).value; } catch (e) { util.reportError(e); throw e; } },
set globalValue(val) { options.store.set(this.name, { value: val, time: Date.now() }); },
get globalValue() {
let val = options.store.get(this.name, {}).value;
if (val != null)
return val;
return this.globalValue = this.defaultValue;
},
set globalValue(val) {
options.store.set(this.name, { value: val, time: Date.now() });
},
/**
* Returns *value* as an array of parsed values if the option type is
@@ -270,8 +255,9 @@ var Option = Class("Option", {
/** @property {string} The option's canonical name. */
name: null,
/** @property {[string]} All names by which this option is identified. */
names: null,
names: Class.Memoize(function () this.realNames),
/**
* @property {string} The option's data type. One of:
@@ -332,7 +318,30 @@ var Option = Class("Option", {
* unless the option is explicitly set either interactively or in an RC
* file or plugin.
*/
defaultValue: null,
defaultValue: Class.Memoize(function () {
let defaultValue = this._defaultValue;
delete this._defaultValue;
if (Set.has(this.modules.config.optionDefaults, this.name))
defaultValue = this.modules.config.optionDefaults[this.name];
if (defaultValue == null && this.getter)
defaultValue = this.getter();
if (defaultValue == undefined)
return null;
if (this.type === "string")
defaultValue = Commands.quote(defaultValue);
if (isObject(defaultValue))
defaultValue = iter(defaultValue).map(function (val) val.map(Option.quote).join(":")).join(",");
if (isArray(defaultValue))
defaultValue = defaultValue.map(Option.quote).join(",");
return this.parse(defaultValue);
}),
/**
* @property {function} The function called when the option value is read.
@@ -757,6 +766,11 @@ var Option = Class("Option", {
EXPORTED_SYMBOLS.push(class_.className);
}, this);
update(BooleanOption.prototype, {
names: Class.Memoize(function ()
array.flatten([[name, "no" + name] for (name in values(this.realNames))]))
});
var OptionHive = Class("OptionHive", Contexts.Hive, {
init: function init(group) {
init.supercall(this, group);
@@ -881,9 +895,8 @@ var Options = Module("options", {
if (!util.isDactyl(Components.stack.caller))
deprecated.warn(add, "options.add", "group.options.add");
util.assert(type in Option.types,
_("option.noSuchType", type),
true);
util.assert(type in Option.types, _("option.noSuchType", type),
false);
if (!extraInfo)
extraInfo = {};

View File

@@ -79,10 +79,13 @@ var ArrayStore = Class("ArrayStore", StoreBase, {
get length() this._object.length,
set: function set(index, value) {
set: function set(index, value, quiet) {
var orig = this._object[index];
this._object[index] = value;
this.fireEvent("change", index);
if (!quiet)
this.fireEvent("change", index);
return orig;
},
push: function push(value) {

View File

@@ -1183,7 +1183,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
rehash: function (args) {
storage.session.commandlineArgs = args;
this.timeout(function () {
this.flushCache();
cache.flushAll();
this.rehashing = true;
let addon = config.addon;
addon.userDisabled = true;