From 2e60561be6e2823b92218c8d28537d2dfcb54d00 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Wed, 10 Dec 2014 19:58:36 -0500 Subject: [PATCH] Cleaning up code for match node --- src/js/parser/javascript/match.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index 4ffce7c..58de80c 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -5,27 +5,24 @@ export default _.extend({}, Base, { type: 'match', _render() { - var parts = this.parts(); + this.contents = { parts: this.parts() }; - if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) { - this.contents = {}; + if (this.anchorStart()) { + this.contents.anchor_start = this.renderLabel('Start of line') + .addClass('anchor'); + } - if (this.anchorStart()) { - this.contents.anchor_start = this.renderLabel('Start of line') - .addClass('anchor'); - } + if (this.anchorEnd()) { + this.contents.anchor_end = this.renderLabel('End of line') + .addClass('anchor'); + } - this.contents.parts = _.map(parts, (function(part) { + if (this.contents.anchor_start || this.contents.anchor_end || this.contents.parts.length !== 1) { + _.each(this.contents.parts, (function(part) { part.render(this.container.group()); - return part; }).bind(this)); - - if (this.anchorEnd()) { - this.contents.anchor_end = this.renderLabel('End of line') - .addClass('anchor'); - } } else { - this.proxy(parts[0]); + this.proxy(this.contents.parts[0]); } }, @@ -34,7 +31,7 @@ export default _.extend({}, Base, { _.invoke(this.contents.parts, 'position'); - items = _(this.contents).values().flatten().value(); + items = _(this.contents).at('anchor_start', 'parts', 'anchor_end').flatten().compact().value(); this.spaceHorizontally(items, { padding: 10 });