Cleaning up some of the arrow function syntax

Don't need to use `return` as much as I had been
This commit is contained in:
Jeff Avallone 2016-07-26 22:41:34 -04:00
parent 2ceb94fc42
commit 1b22d0b717
8 changed files with 42 additions and 61 deletions

View File

@ -1,8 +1,6 @@
export default { export default {
_render() { _render() {
return this.renderLabel(this.label).then(label => { return this.renderLabel(this.label).then(label => label.addClass('anchor'));
return label.addClass('anchor');
});
}, },
setup() { setup() {

View File

@ -28,9 +28,9 @@ export default {
this.partContainer = this.container.group(); this.partContainer = this.container.group();
// Renders each part of the charset into the part container. // Renders each part of the charset into the part container.
return Promise.all(_.map(this.elements, part => { return Promise.all(_.map(this.elements,
return part.render(this.partContainer.group()); part => part.render(this.partContainer.group())
})) ))
.then(() => { .then(() => {
// Space the parts of the charset vertically in the part container. // Space the parts of the charset vertically in the part container.
util.spaceVertically(this.elements, { util.spaceVertically(this.elements, {
@ -54,9 +54,8 @@ export default {
// and text value of the part, so `[aa]` will have only one item, but // 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 // `[a\x61]` will contain two since the first matches "a" and the second
// matches 0x61 (even though both are an "a"). // matches 0x61 (even though both are an "a").
this.elements = _.uniqBy(this.properties.parts.elements, part => { this.elements = _.uniqBy(this.properties.parts.elements,
return `${part.type}:${part.textValue}`; part => `${part.type}:${part.textValue}`);
});
// Include a warning for charsets that attempt to match `\c` followed by // Include a warning for charsets that attempt to match `\c` followed by
// any character other than A-Z (case insensitive). Charsets like `[\c@]` // any character other than A-Z (case insensitive). Charsets like `[\c@]`

View File

@ -33,9 +33,7 @@ export default {
items; items;
// Render each of the match fragments. // Render each of the match fragments.
partPromises = _.map(this.parts, part => { partPromises = _.map(this.parts, part => part.render(this.container.group()));
return part.render(this.container.group());
});
items = _(partPromises).compact().value(); items = _(partPromises).compact().value();

View File

@ -15,9 +15,9 @@ export default {
.translate(20, 0)); .translate(20, 0));
// Renders each match into the match container. // Renders each match into the match container.
return Promise.all(_.map(this.matches, match => { return Promise.all(_.map(this.matches,
return match.render(matchContainer.group()); match => match.render(matchContainer.group())
})) ))
.then(() => { .then(() => {
let containerBox, let containerBox,
paths; paths;
@ -30,9 +30,7 @@ export default {
containerBox = this.getBBox(); containerBox = this.getBBox();
// Creates the curves from the side lines for each match. // Creates the curves from the side lines for each match.
paths = _.map(this.matches, match => { paths = _.map(this.matches, match => this.makeCurve(containerBox, match));
return this.makeCurve(containerBox, match)
});
// Add side lines to the list of paths. // Add side lines to the list of paths.
paths.push(this.makeSide(containerBox, _.first(this.matches))); 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 // Create connections from side lines to each match and render into
// the match container. // the match container.
paths = _.map(this.matches, match => { paths = _.map(this.matches, match => this.makeConnector(containerBox, match));
return this.makeConnector(containerBox, match);
});
matchContainer.prepend( matchContainer.prepend(
matchContainer.path(paths.join(''))); matchContainer.path(paths.join('')));
}); });
@ -124,10 +120,10 @@ export default {
this.proxy = this.properties.match; this.proxy = this.properties.match;
} else { } else {
// Merge all the match nodes into one array. // Merge all the match nodes into one array.
this.matches = [this.properties.match] this.matches = [this.properties.match].concat(
.concat(_.map(this.properties.alternates.elements, element => { _.map(this.properties.alternates.elements,
return element.properties.match; element => element.properties.match)
})); );
} }
} }
}; };

View File

@ -47,9 +47,9 @@ export default {
setup() { setup() {
// Convert list of flags into text describing each flag. // Convert list of flags into text describing each flag.
this.flags = _(this.properties.flags.textValue).uniq().sort().map(flag => { this.flags = _(this.properties.flags.textValue)
return this.flagLabels[flag]; .uniq().sort()
}).value(); .map(flag => this.flagLabels[flag]).value();
this.regexp = this.properties.regexp this.regexp = this.properties.regexp
} }

View File

@ -38,12 +38,10 @@ export default {
// Render the contained regexp. // Render the contained regexp.
return this.regexp.render(this.container.group()) return this.regexp.render(this.container.group())
.then(() => {
// Create the labeled box around the regexp. // Create the labeled box around the regexp.
return this.renderLabeledBox(label, this.regexp, { .then(() => this.renderLabeledBox(label, this.regexp, {
padding: 10 padding: 10
}); }));
});
}, },
// Returns the label for the subexpression. // Returns the label for the subexpression.

View File

@ -183,9 +183,9 @@ export default class Regexper {
// //
// - __warnings__ - Array of warning messages to display. // - __warnings__ - Array of warning messages to display.
displayWarnings(warnings) { displayWarnings(warnings) {
this.warnings.innerHTML = _.map(warnings, warning => { this.warnings.innerHTML = _.map(warnings, warning => (
return `<li class="inline-icon">${util.icon("#warning")}${warning}</li>`; `<li class="inline-icon">${util.icon("#warning")}${warning}</li>`
}).join(''); )).join('');
} }
// Render regular expression // Render regular expression
@ -200,9 +200,7 @@ export default class Regexper {
if (this.running) { if (this.running) {
this.running.cancel(); this.running.cancel();
return util.wait(10).then(() => { return util.wait(10).then(() => this.renderRegexp(expression));
return this.renderRegexp(expression);
});
} }
this.state = 'is-loading'; this.state = 'is-loading';
@ -225,9 +223,7 @@ export default class Regexper {
throw message; throw message;
}) })
// When parsing is successful, render the parsed expression. // When parsing is successful, render the parsed expression.
.then(parser => { .then(parser => parser.render())
return parser.render();
})
// Once rendering is complete: // Once rendering is complete:
// - Update links // - Update links
// - Display any warnings // - Display any warnings

View File

@ -43,17 +43,15 @@ function spaceHorizontally(items, options) {
padding: 0 padding: 0
}); });
values = _.map(items, item => { values = _.map(items, item => ({
return {
box: normalizeBBox(item.getBBox()), box: normalizeBBox(item.getBBox()),
item item
}; }));
});
// Calculate where the axis points should be positioned vertically. // Calculate where the axis points should be positioned vertically.
verticalCenter = _.reduce(values, (center, { box }) => { verticalCenter = _.reduce(values,
return Math.max(center, box.ay); (center, { box }) => Math.max(center, box.ay),
}, 0); 0);
// Position items with padding between them and aligned their axis points. // Position items with padding between them and aligned their axis points.
_.reduce(values, (offset, { item, box }) => { _.reduce(values, (offset, { item, box }) => {
@ -76,17 +74,15 @@ function spaceVertically(items, options) {
padding: 0 padding: 0
}); });
values = _.map(items, item => { values = _.map(items, item => ({
return {
box: item.getBBox(), box: item.getBBox(),
item item
}; }));
});
// Calculate where the center of each item should be positioned horizontally. // Calculate where the center of each item should be positioned horizontally.
horizontalCenter = _.reduce(values, (center, { box }) => { horizontalCenter = _.reduce(values,
return Math.max(center, box.cx); (center, { box }) => Math.max(center, box.cx),
}, 0); 0);
// Position items with padding between them and align their centers. // Position items with padding between them and align their centers.
_.reduce(values, (offset, { item, box }) => { _.reduce(values, (offset, { item, box }) => {