1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-13 07:05:46 +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

@@ -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.
*