1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-24 04:22:26 +01:00

Move util.identity to the base module.

Most other functions of its ilk live there.
This commit is contained in:
Doug Kearns
2015-06-11 03:10:16 +10:00
parent 6ca1cc3d08
commit 59613afb27
20 changed files with 49 additions and 46 deletions

View File

@@ -105,7 +105,7 @@ var AbbrevHive = Class("AbbrevHive", Contexts.Hive, {
},
/** @property {boolean} True if there are no abbreviations. */
get empty() { return !values(this._store).find(util.identity); },
get empty() { return !values(this._store).find(identity); },
/**
* Adds a new abbreviation.
@@ -251,7 +251,7 @@ var Abbreviations = Module("abbreviations", {
let match = this._match.exec(text);
if (match)
return this.hives.map(h => h.get(mode, match[2] || match[4] || match[6]))
.find(util.identity);
.find(identity);
return null;
},

View File

@@ -438,7 +438,7 @@ var Bookmarks = Module("bookmarks", {
for (b of bookmarkcache)
if (b.tags))
.flatten().uniq().array;
context.keys = { text: util.identity, description: util.identity };
context.keys = { text: identity, description: identity };
},
type: CommandOption.LIST
};
@@ -705,7 +705,7 @@ var Bookmarks = Module("bookmarks", {
}
catch (e) {}
return null;
}).filter(util.identity);
}).filter(identity);
};
});
};
@@ -742,7 +742,7 @@ var Bookmarks = Module("bookmarks", {
let ctxt = context.fork(name, 0);
ctxt.title = [/*L*/desc + " Suggestions"];
ctxt.keys = { text: util.identity, description: function () "" };
ctxt.keys = { text: identity, description: function () "" };
ctxt.compare = CompletionContext.Sort.unsorted;
ctxt.filterFunc = null;

View File

@@ -166,7 +166,7 @@ var CommandWidgets = Class("CommandWidgets", {
this.elements[obj.name] = obj;
function get(prefix, map, id) {
return (obj.getElement || util.identity)(map[id] || document.getElementById(prefix + id));
return (obj.getElement || identity)(map[id] || document.getElementById(prefix + id));
}
this.active.__defineGetter__(obj.name, () => this.activeGroup[obj.name][obj.name]);
@@ -200,7 +200,7 @@ var CommandWidgets = Class("CommandWidgets", {
else {
highlight.highlightNode(elem,
(val[0] != null ? val[0] : obj.defaultGroup)
.split(/\s/).filter(util.identity)
.split(/\s/).filter(identity)
.map(g => g + " " + nodeSet.group + g)
.join(" "));
elem.value = val[1];

View File

@@ -256,7 +256,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
{
argCount: "*",
completer: function (context, args) {
context.keys.text = util.identity;
context.keys.text = identity;
context.keys.description = function () {
return seen[this.text] + /*L*/" matching items";
};
@@ -662,7 +662,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
*/
generateHelp: function generateHelp(obj, extraHelp, str, specOnly) {
let link, tag, spec;
link = tag = spec = util.identity;
link = tag = spec = identity;
let args = null;
if (obj instanceof Command) {
@@ -1286,7 +1286,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
template.map(iter(dactyl.indices),
([name, iter]) =>
["dl", { insertafter: name + "-index" },
template.map(iter(), util.identity)],
template.map(iter(), identity)],
"\n\n")]);
}, true);

View File

@@ -777,7 +777,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
completion: function initCompletion() {
completion.register = function complete_register(context) {
context = context.fork("registers");
context.keys = { text: util.identity, description: editor.bound.getRegister };
context.keys = { text: identity, description: editor.bound.getRegister };
context.match = function (r) {
return !this.filter || this.filter.contains(r);
@@ -1413,7 +1413,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
let res = {};
services.spell.getDictionaryList(res, {});
context.completions = res.value;
context.keys = { text: util.identity, description: util.identity };
context.keys = { text: identity, description: identity };
}
});
},

View File

@@ -331,7 +331,7 @@ var History = Module("history", {
completion.domain = context => {
context.anchored = false;
context.compare = (a, b) => String.localeCompare(a.key, b.key);
context.keys = { text: util.identity, description: util.identity,
context.keys = { text: identity, description: identity,
key: function (host) host.split(".").reverse().join(".") };
// FIXME: Schema-specific

View File

@@ -196,7 +196,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
*/
add: function (modes, keys, description, action, extra={}) {
modes = Array.concat(modes);
if (!modes.every(util.identity))
if (!modes.every(identity))
throw TypeError(/*L*/"Invalid modes: " + modes);
let map = Map(modes, keys, description, action, extra);

View File

@@ -301,14 +301,14 @@ var Marks = Module("marks", {
"(" + Math.round(mark.offset.x * 100),
Math.round(mark.offset.y * 100) + ")",
(tab && "tab: " + tabs.index(tab))
].filter(util.identity).join(", ");
].filter(identity).join(", ");
if (mark.position)
return [name, mark.location,
"(" + Math.round(mark.position.x * 100) + "%",
Math.round(mark.position.y * 100) + "%)",
(tab && "tab: " + tabs.index(tab))
].filter(util.identity).join(", ");
].filter(identity).join(", ");
},
isLocalMark: bind("test", /^[a-z`']$/),

View File

@@ -201,6 +201,7 @@ defineModule("base", {
"deprecated",
"endModule",
"hasOwnProperty",
"identity",
"isArray",
"isGenerator",
"isObject",
@@ -724,6 +725,14 @@ function call(fn, self, ...args) {
return fn;
}
/**
* Returns *val*.
*
* @param {*} val
* @returns {*}
*/
function identity(val) { return val; }
/**
* Memoizes an object property value.
*
@@ -1632,7 +1641,7 @@ update(iter, {
compact: function compact(iter) (item for (item of iter) if (item != null)),
every: function every(iter, pred, self) {
pred = pred || util.identity;
pred = pred || identity;
for (let elem of iter)
if (!pred.call(self, elem))
return false;
@@ -1640,7 +1649,7 @@ update(iter, {
},
some: function every(iter, pred, self) {
pred = pred || util.identity;
pred = pred || identity;
for (let elem of iter)
if (pred.call(self, elem))
return true;

View File

@@ -2552,7 +2552,7 @@ var Buffer = Module("Buffer", {
res = iter.find(filter.matcher(doc),
elem => ((elem.nodeValue || elem.textContent).trim() == line &&
DOM(elem).display != "none"))
|| iter.nth(filter.matcher(doc), util.identity, line - 1);
|| iter.nth(filter.matcher(doc), identity, line - 1);
if (res)
break;
}

View File

@@ -917,7 +917,7 @@ var Commands = Module("commands", {
* @returns {Command}
*/
get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full))
.find(util.identity),
.find(identity),
/**
* Returns true if a command invocation contains a URL referring to the
@@ -1569,7 +1569,7 @@ var Commands = Module("commands", {
let quote = RegExp.$2;
context.quote = null;
context.offset -= idx;
context.filter = str.substr(0, idx) + (quote ? Option.quote : util.identity)(context.filter);
context.filter = str.substr(0, idx) + (quote ? Option.quote : identity)(context.filter);
context.fork("ex", 0, completion, "ex");
};

View File

@@ -366,7 +366,7 @@ var CompletionContext = Class("CompletionContext", {
get createRow() { return this._createRow || template.completionRow; }, // XXX
set createRow(createRow) { return this._createRow = createRow; },
get filterFunc() { return this._filterFunc || util.identity; },
get filterFunc() { return this._filterFunc || identity; },
set filterFunc(val) { this._filterFunc = val; },
get filter() {
@@ -595,7 +595,7 @@ var CompletionContext = Class("CompletionContext", {
if (this._substrings)
return this._substrings;
let fixCase = this.ignoreCase ? String.toLowerCase : util.identity;
let fixCase = this.ignoreCase ? String.toLowerCase : identity;
let text = fixCase(items[0].text);
let filter = fixCase(this.filter);
@@ -1035,7 +1035,7 @@ var Completion = Module("completion", {
if (/^jar:[^!]*$/.test(context.filter)) {
context.advance(4);
context.quote = context.quote || ["", util.identity, ""];
context.quote = context.quote || ["", identity, ""];
let quote = context.quote[1];
context.quote[1] = function quote_1(str) {
return quote(str.replace(/!/g, escape));
@@ -1185,7 +1185,7 @@ var Completion = Module("completion", {
});
});
let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g");
let re = RegExp(tokens.filter(identity).map(util.regexp.escape).join("|"), "g");
function highlight(item, text, i) {
return process[i].call(this, item, template.highlightRegexp(text, re));
}

View File

@@ -528,7 +528,7 @@ var Contexts = Module("contexts", {
});
}
let process = util.identity;
let process = identity;
if (callable(params))
var makeParams = function makeParams(self, args) {
@@ -663,7 +663,7 @@ var Contexts = Module("contexts", {
if (!group.builtin && args.has("-args")) {
group.argsExtra = contexts.bindMacro({ literalArg: "return " + args["-args"] },
"-javascript", util.identity);
"-javascript", identity);
group.args = args["-args"];
}

View File

@@ -659,7 +659,7 @@ var DOM = Class("DOM", {
res.push({}.toString.call(elem));
}
}, this);
res = template.map(res, util.identity, ",");
res = template.map(res, identity, ",");
return color ? res : res.join("");
},

View File

@@ -165,7 +165,7 @@ var Download = Class("Download", {
let val = this._compare[order.substr(1)](this, other);
return (order[0] == "-") ? -val : val;
}, this).find(util.identity) || 0,
}, this).find(identity) || 0,
timeRemaining: Infinity,

View File

@@ -584,7 +584,7 @@ var IO = Module("io", {
let args = Ary(util.range(0, func.length))
.map(bind("createTempFile", this, ext, label)).array;
try {
if (!args.every(util.identity))
if (!args.every(identity))
return false;
var res = func.apply(self || this, args);
}
@@ -979,7 +979,7 @@ unlet s:cpo_save
completion.charset = context => {
context.anchored = false;
context.keys = {
text: util.identity,
text: identity,
description: charset => io.charsetTitle(charset)
};
context.completions = io.charsets;
@@ -1163,7 +1163,7 @@ unlet s:cpo_save
});
options.add(["cdpath", "cd"],
"List of directories searched when executing :cd",
"stringlist", ["."].concat(services.environment.get("CDPATH").split(/[:;]/).filter(util.identity)).join(","),
"stringlist", ["."].concat(services.environment.get("CDPATH").split(/[:;]/).filter(identity)).join(","),
{
get files() {
return this.value.map(path => File(path, modules.io.cwd))

View File

@@ -1322,7 +1322,7 @@ var Options = Module("options", {
[option.stringValue, _("option.currentValue")],
[option.stringDefaultValue, _("option.defaultValue")]
].filter(f => f[0] !== "");
context.quote = ["", util.identity, ""];
context.quote = ["", identity, ""];
});
}

View File

@@ -620,7 +620,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
context.title = ["Domain"];
context.anchored = false;
context.compare = modules.CompletionContext.Sort.unsorted;
context.keys = { text: util.identity, description: util.identity };
context.keys = { text: identity, description: identity };
context.completions = res;
};
},

View File

@@ -156,7 +156,7 @@ var Hive = Class("Hive", {
sheet.sites = filter;
}
else {
sheet = Sheet(name, styles._id++, filter.filter(util.identity), String(css), this, agent);
sheet = Sheet(name, styles._id++, filter.filter(identity), String(css), this, agent);
this.sheets.push(sheet);
}
@@ -414,7 +414,7 @@ var Styles = Module("Styles", {
context.generate = () => values(group.sites);
context.keys.text = util.identity;
context.keys.text = identity;
context.keys.description = function (site) {
return this.sheets.length + /*L*/" sheet" +
(this.sheets.length == 1 ? "" : "s") + ": " +

View File

@@ -98,6 +98,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
haveGecko: deprecated("config.haveGecko", { get: function haveGecko() config.bound.haveGecko }),
OS: deprecated("config.OS", { get: function OS() config.OS }),
identity: deprecated("identity", { get: function identity() global.identity }),
dactyl: update(function dactyl(obj) {
if (obj)
var global = Class.objectGlobal(obj);
@@ -346,7 +348,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
return this[this.length - 1];
});
let unknown = util.identity;
let unknown = identity;
if (!keepUnknown)
unknown = () => "";
@@ -395,7 +397,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
let [, flags, name] = /^((?:[a-z]-)*)(.*)/.exec(macro);
flags = new RealSet(flags);
let quote = util.identity;
let quote = identity;
if (flags.has("q"))
quote = function quote(obj) {
return typeof obj === "number" ? obj : JSON.stringify(obj);
@@ -851,14 +853,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
});
},
/**
* The identity function.
*
* @param {Object} k
* @returns {Object}
*/
identity: function identity(k) k,
/**
* Returns the intersection of two rectangles.
*