From 1b22d0b717c2aa8ff88056540cfc6e382e9514d2 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Tue, 26 Jul 2016 22:41:34 -0400 Subject: [PATCH] Cleaning up some of the arrow function syntax Don't need to use `return` as much as I had been --- src/js/parser/javascript/anchor.js | 4 +--- src/js/parser/javascript/charset.js | 11 +++++----- src/js/parser/javascript/match.js | 4 +--- src/js/parser/javascript/regexp.js | 22 ++++++++------------ src/js/parser/javascript/root.js | 6 +++--- src/js/parser/javascript/subexp.js | 10 ++++----- src/js/regexper.js | 14 +++++-------- src/js/util.js | 32 +++++++++++++---------------- 8 files changed, 42 insertions(+), 61 deletions(-) diff --git a/src/js/parser/javascript/anchor.js b/src/js/parser/javascript/anchor.js index d59cfde..a5c46ba 100644 --- a/src/js/parser/javascript/anchor.js +++ b/src/js/parser/javascript/anchor.js @@ -1,8 +1,6 @@ export default { _render() { - return this.renderLabel(this.label).then(label => { - return label.addClass('anchor'); - }); + return this.renderLabel(this.label).then(label => label.addClass('anchor')); }, setup() { diff --git a/src/js/parser/javascript/charset.js b/src/js/parser/javascript/charset.js index a021126..465d482 100644 --- a/src/js/parser/javascript/charset.js +++ b/src/js/parser/javascript/charset.js @@ -28,9 +28,9 @@ export default { this.partContainer = this.container.group(); // Renders each part of the charset into the part container. - return Promise.all(_.map(this.elements, part => { - return part.render(this.partContainer.group()); - })) + return Promise.all(_.map(this.elements, + part => part.render(this.partContainer.group()) + )) .then(() => { // Space the parts of the charset vertically in the part container. util.spaceVertically(this.elements, { @@ -54,9 +54,8 @@ export default { // and text value of the part, so `[aa]` will have only one item, but // `[a\x61]` will contain two since the first matches "a" and the second // matches 0x61 (even though both are an "a"). - this.elements = _.uniqBy(this.properties.parts.elements, part => { - return `${part.type}:${part.textValue}`; - }); + this.elements = _.uniqBy(this.properties.parts.elements, + part => `${part.type}:${part.textValue}`); // Include a warning for charsets that attempt to match `\c` followed by // any character other than A-Z (case insensitive). Charsets like `[\c@]` diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index c01ed60..c951b23 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -33,9 +33,7 @@ export default { items; // Render each of the match fragments. - partPromises = _.map(this.parts, part => { - return part.render(this.container.group()); - }); + partPromises = _.map(this.parts, part => part.render(this.container.group())); items = _(partPromises).compact().value(); diff --git a/src/js/parser/javascript/regexp.js b/src/js/parser/javascript/regexp.js index 6974482..89fad23 100644 --- a/src/js/parser/javascript/regexp.js +++ b/src/js/parser/javascript/regexp.js @@ -15,9 +15,9 @@ export default { .translate(20, 0)); // Renders each match into the match container. - return Promise.all(_.map(this.matches, match => { - return match.render(matchContainer.group()); - })) + return Promise.all(_.map(this.matches, + match => match.render(matchContainer.group()) + )) .then(() => { let containerBox, paths; @@ -30,9 +30,7 @@ export default { containerBox = this.getBBox(); // Creates the curves from the side lines for each match. - paths = _.map(this.matches, match => { - return this.makeCurve(containerBox, match) - }); + paths = _.map(this.matches, match => this.makeCurve(containerBox, match)); // Add side lines to the list of paths. paths.push(this.makeSide(containerBox, _.first(this.matches))); @@ -46,9 +44,7 @@ export default { // Create connections from side lines to each match and render into // the match container. - paths = _.map(this.matches, match => { - return this.makeConnector(containerBox, match); - }); + paths = _.map(this.matches, match => this.makeConnector(containerBox, match)); matchContainer.prepend( matchContainer.path(paths.join(''))); }); @@ -124,10 +120,10 @@ export default { this.proxy = this.properties.match; } else { // Merge all the match nodes into one array. - this.matches = [this.properties.match] - .concat(_.map(this.properties.alternates.elements, element => { - return element.properties.match; - })); + this.matches = [this.properties.match].concat( + _.map(this.properties.alternates.elements, + element => element.properties.match) + ); } } }; diff --git a/src/js/parser/javascript/root.js b/src/js/parser/javascript/root.js index c50d720..b9e8004 100644 --- a/src/js/parser/javascript/root.js +++ b/src/js/parser/javascript/root.js @@ -47,9 +47,9 @@ export default { setup() { // Convert list of flags into text describing each flag. - this.flags = _(this.properties.flags.textValue).uniq().sort().map(flag => { - return this.flagLabels[flag]; - }).value(); + this.flags = _(this.properties.flags.textValue) + .uniq().sort() + .map(flag => this.flagLabels[flag]).value(); this.regexp = this.properties.regexp } diff --git a/src/js/parser/javascript/subexp.js b/src/js/parser/javascript/subexp.js index c4595ba..4c63439 100644 --- a/src/js/parser/javascript/subexp.js +++ b/src/js/parser/javascript/subexp.js @@ -38,12 +38,10 @@ export default { // Render the contained regexp. return this.regexp.render(this.container.group()) - .then(() => { - // Create the labeled box around the regexp. - return this.renderLabeledBox(label, this.regexp, { - padding: 10 - }); - }); + // Create the labeled box around the regexp. + .then(() => this.renderLabeledBox(label, this.regexp, { + padding: 10 + })); }, // Returns the label for the subexpression. diff --git a/src/js/regexper.js b/src/js/regexper.js index f9f61d9..6a6900d 100644 --- a/src/js/regexper.js +++ b/src/js/regexper.js @@ -183,9 +183,9 @@ export default class Regexper { // // - __warnings__ - Array of warning messages to display. displayWarnings(warnings) { - this.warnings.innerHTML = _.map(warnings, warning => { - return `
  • ${util.icon("#warning")}${warning}
  • `; - }).join(''); + this.warnings.innerHTML = _.map(warnings, warning => ( + `
  • ${util.icon("#warning")}${warning}
  • ` + )).join(''); } // Render regular expression @@ -200,9 +200,7 @@ export default class Regexper { if (this.running) { this.running.cancel(); - return util.wait(10).then(() => { - return this.renderRegexp(expression); - }); + return util.wait(10).then(() => this.renderRegexp(expression)); } this.state = 'is-loading'; @@ -225,9 +223,7 @@ export default class Regexper { throw message; }) // When parsing is successful, render the parsed expression. - .then(parser => { - return parser.render(); - }) + .then(parser => parser.render()) // Once rendering is complete: // - Update links // - Display any warnings diff --git a/src/js/util.js b/src/js/util.js index 9d48f8d..49b2a57 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -43,17 +43,15 @@ function spaceHorizontally(items, options) { padding: 0 }); - values = _.map(items, item => { - return { - box: normalizeBBox(item.getBBox()), - item - }; - }); + values = _.map(items, item => ({ + box: normalizeBBox(item.getBBox()), + item + })); // Calculate where the axis points should be positioned vertically. - verticalCenter = _.reduce(values, (center, { box }) => { - return Math.max(center, box.ay); - }, 0); + verticalCenter = _.reduce(values, + (center, { box }) => Math.max(center, box.ay), + 0); // Position items with padding between them and aligned their axis points. _.reduce(values, (offset, { item, box }) => { @@ -76,17 +74,15 @@ function spaceVertically(items, options) { padding: 0 }); - values = _.map(items, item => { - return { - box: item.getBBox(), - item - }; - }); + values = _.map(items, item => ({ + box: item.getBBox(), + item + })); // Calculate where the center of each item should be positioned horizontally. - horizontalCenter = _.reduce(values, (center, { box }) => { - return Math.max(center, box.cx); - }, 0); + horizontalCenter = _.reduce(values, + (center, { box }) => Math.max(center, box.cx), + 0); // Position items with padding between them and align their centers. _.reduce(values, (offset, { item, box }) => {