1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 23:04:13 +01:00

ES6-ify some things. Still a long way to go...

This commit is contained in:
Kris Maglione
2015-12-20 02:02:54 -08:00
parent 65725c9516
commit 27cdeb1885
28 changed files with 411 additions and 303 deletions

View File

@@ -366,23 +366,21 @@ var Abbreviations = Module("abbreviations", {
}
],
serialize: function () {
return Ary(abbreviations.userHives)
return abbreviations.userHives
.filter(h => h.persist)
.map(hive => [
{
command: this.name,
arguments: [abbr.lhs],
literalArg: abbr.rhs,
options: {
"-group": hive.name == "user" ? undefined : hive.name,
"-javascript": callable(abbr.rhs) ? null : undefined
}
}
for (abbr of hive.merged)
if (abbr.modesEqual(modes))
]).
flatten().array;
}
.flatMap(hive =>
hive.merged
.filter(abbr => abbr.modesEqual(modes))
.map(abbr => ({
command: this.name,
arguments: [abbr.lhs],
literalArg: abbr.rhs,
options: {
"-group": hive.name == "user" ? undefined : hive.name,
"-javascript": callable(abbr.rhs) ? null : undefined
}
})));
},
});
commands.add([ch + "una[bbreviate]"],

View File

@@ -436,10 +436,9 @@ var Bookmarks = Module("bookmarks", {
names: ["-tags", "-T"],
description: "A comma-separated list of tags",
completer: function tags(context) {
context.generate = () => Ary(b.tags
for (b of bookmarkcache)
if (b.tags))
.flatten().uniq().array;
context.generate = () => new RealSet(Array.from(bookmarkcache)
.flatMap(b.tags));
context.keys = { text: identity, description: identity };
},
type: CommandOption.LIST

View File

@@ -243,12 +243,12 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
{ argCount: "0" });
},
mappings: function initMappings(dactyl, modules, window) {
let openModes = Ary.toObject([
[dactyl.CURRENT_TAB, ""],
[dactyl.NEW_TAB, "tab"],
[dactyl.NEW_BACKGROUND_TAB, "background tab"],
[dactyl.NEW_WINDOW, "win"]
]);
let openModes = {
[dactyl.CURRENT_TAB]: "",
[dactyl.NEW_TAB]: "tab",
[dactyl.NEW_BACKGROUND_TAB]: "background tab",
[dactyl.NEW_WINDOW]: "win",
};
function open(mode, args) {
if (dactyl.forceTarget in openModes)

View File

@@ -240,8 +240,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let name = commands.add(params.name, params.description,
function (args) {
let results = Ary(params.iterate(args))
.sort((a, b) => String.localeCompare(a.name, b.name));
let results = Array.from(params.iterate(args))
.sort((a, b) => String.localeCompare(a.name, b.name));
let filters = args.map(arg => {
let re = util.regexp.escape(arg);
@@ -261,22 +261,24 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
return seen[this.text] + /*L*/" matching items";
};
context.ignoreCase = true;
let seen = {};
context.completions = Ary(keys(item).join(" ").toLowerCase().split(/[()\s]+/)
for (item of params.iterate(args)))
.flatten()
.map(function (k) {
seen[k] = (seen[k] || 0) + 1;
return k;
}).uniq();
context.completions = new RealSet(
Array.from(params.iterate(args))
.flatMap(item => Object.keys(item).join(" ")
.toLowerCase().split(/[()\s]+/))
.map(k => {
seen[k] = (seen[k] || 0) + 1;
return k;
}));
},
options: params.options || []
});
if (params.index)
this.indices[params.index] = function* () {
let results = Ary((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs()))
.array.sort((a, b) => String.localeCompare(a.name, b.name));
let results = Array.from((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs()))
.sort((a, b) => String.localeCompare(a.name, b.name));
for (let obj of results) {
let res = dactyl.generateHelp(obj, null, null, true);
@@ -646,7 +648,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* Initialize the help system.
*/
initHelp: function initHelp() {
util.dumpStack('INIT HELP');
if ("noscriptOverlay" in window)
window.noscriptOverlay.safeAllow("dactyl:", true, false);
@@ -1415,11 +1416,13 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
// FIXME: cleanup
cleanupValue: config.cleanups.guioptions ||
"rb" + [k for ([k, v] of iter(groups[1].opts))
if (!Dactyl.isToolbarHidden(document.getElementById(v[1][0])))].join(""),
"rb" + Object.entries(groups[1].opts)
.filter(([k, v]) => !Dactyl.isToolbarHidden(document.getElementById(v[1][0])))
.map(([k]) => k)
.join(""),
values: Ary(groups).map(g => [[k, v[0]] for ([k, v] of iter(g.opts))])
.flatten(),
values: groups.flatMap(g => Object.entries(g.opts)
.map(([k, v]) => [k, v[0]])),
setter: function (value) {
for (let group of groups)

View File

@@ -23,10 +23,10 @@ var EventHive = Class("EventHive", Contexts.Hive, {
},
_events: function _events(event, callback) {
if (!isObject(event))
var [self, events] = [null, Ary.toObject([[event, callback]])];
if (isObject(event))
var [self, events] = [event, event[callback || "events"]];
else
[self, events] = [event, event[callback || "events"]];
[self, events] = [null, { [event]: callback }];
if (hasOwnProp(events, "input") && !hasOwnProp(events, "dactyl-input"))
events["dactyl-input"] = events.input;
@@ -1141,7 +1141,7 @@ var Events = Module("events", {
return this.value.filter(f => f(buffer.documentURI));
});
memoize(this, "pass", function () {
return new RealSet(Ary.flatten(this.filters.map(f => f.keys)));
return new RealSet(this.filters.flatMap(f => f.keys));
});
memoize(this, "commandHive", function hive() {
return Hive(this.filters, "command");

View File

@@ -1379,7 +1379,8 @@ var Hints = Module("hints", {
},
validator: function (value) {
let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify);
return Option.validIf(Ary.uniq(values).length === values.length && values.length > 1,
return Option.validIf(new RealSet(values).size === values.length && values.length > 1,
_("option.hintkeys.duplicate"));
}
});

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2015 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -290,7 +290,7 @@ var History = Module("history", {
description: "The sort order of the results",
completer: function (context) {
context.compare = CompletionContext.Sort.unsorted;
return Ary.flatten([
return [
"annotation",
"date",
"date added",
@@ -300,10 +300,10 @@ var History = Module("history", {
"title",
"uri",
"visitcount"
].map(order => [
["+" + order.replace(" ", ""), /*L*/"Sort by " + order + " ascending"],
["-" + order.replace(" ", ""), /*L*/"Sort by " + order + " descending"]
]));
].flatMap(order => [
["+" + order.replace(" ", ""), /*L*/"Sort by " + order + " ascending"],
["-" + order.replace(" ", ""), /*L*/"Sort by " + order + " descending"]
]);
}
}
],

View File

@@ -17,7 +17,9 @@ var ProcessorStack = Class("ProcessorStack", {
events.dbg("STACK " + mode);
let main = { __proto__: mode.main, params: mode.params };
this.modes = Ary([mode.params.keyModes, main, mode.main.allBases.slice(1)]).flatten().compact();
this.modes = Ary([mode.params.keyModes,
main,
mode.main.allBases.slice(1)]).flatten().compact();
if (builtin)
hives = hives.filter(h => h.name === "builtin");

View File

@@ -116,7 +116,7 @@ var Map = Class("Map", {
return this.keys.indexOf(name) >= 0;
},
get keys() { return Ary.flatten(this.names.map(mappings.bound.expand)); },
get keys() { return this.names.flatMap(mappings.bound.expand); },
/**
* Execute the action for this mapping.
@@ -404,7 +404,7 @@ var Mappings = Module("mappings", {
iterate: function* (mode) {
let seen = new RealSet;
for (let hive of this.hives.iterValues())
for (let map of Ary.iterValues(hive.getStack(mode)))
for (let map of hive.getStack(mode))
if (!seen.add(map.name))
yield map;
},
@@ -646,26 +646,24 @@ var Mappings = Module("mappings", {
if (this.name != "map")
return [];
else
return Ary(mappings.userHives)
return mappings.userHives
.filter(h => h.persist)
.map(hive => [
{
command: "map",
options: {
"-count": map.count ? null : undefined,
"-description": map.description,
"-group": hive.name == "user" ? undefined : hive.name,
"-modes": uniqueModes(map.modes),
"-silent": map.silent ? null : undefined
},
arguments: [map.names[0]],
literalArg: map.rhs,
ignoreDefaults: true
}
for (map of userMappings(hive))
if (map.persist)
])
.flatten().array;
.flatMap(hive =>
Array.from(userMappings(hive))
.filter(map => map.persist)
.map(map => ({
command: "map",
options: {
"-count": map.count ? null : undefined,
"-description": map.description,
"-group": hive.name == "user" ? undefined : hive.name,
"-modes": uniqueModes(map.modes),
"-silent": map.silent ? null : undefined
},
arguments: [map.names[0]],
literalArg: map.rhs,
ignoreDefaults: true
})));
}
};
function* userMappings(hive) {
@@ -731,9 +729,11 @@ var Mappings = Module("mappings", {
return Array.concat(value).every(findMode);
},
completer: function () {
return [[Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description]
for (mode of modes.all)
if (!mode.hidden)];
return modes.all.filter(mode => !mode.hidden)
.map(
mode => [Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"),
mode.char]),
mode.description]);
}
};

View File

@@ -685,8 +685,10 @@ var Modes = Module("modes", {
},
get values() {
return Ary.toObject([[m.name.toLowerCase(), m.description]
for (m of modes._modes) if (!m.hidden)]);
return Ary.toObject(
modes._modes.filter(mode => !mode.hidden)
.map(mode => [mode.name.toLowerCase(),
mode.description]));
}
};