Short-circuiting the render of nodes.

This will reduce the depth of nesting of elements (and hopefully make
final positioning easier)
This commit is contained in:
Jeff Avallone 2014-12-10 16:52:57 -05:00
parent 6dcc5f48c4
commit fc7032241f
3 changed files with 61 additions and 37 deletions

View File

@ -5,6 +5,9 @@ export default _.extend({}, Base, {
type: 'match', type: 'match',
render() { render() {
var parts = this.parts();
if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) {
this.contents = {}; this.contents = {};
if (this.anchorStart()) { if (this.anchorStart()) {
@ -12,7 +15,7 @@ export default _.extend({}, Base, {
.addClass('anchor'); .addClass('anchor');
} }
this.contents.parts = _.map(this.parts(), (function(part) { this.contents.parts = _.map(parts, (function(part) {
part.setContainer(this.container.group()); part.setContainer(this.container.group());
part.render(); part.render();
return part; return part;
@ -22,16 +25,22 @@ export default _.extend({}, Base, {
this.contents.anchor_end = this.renderLabel(this.container, 'End of line') this.contents.anchor_end = this.renderLabel(this.container, 'End of line')
.addClass('anchor'); .addClass('anchor');
} }
} else {
this.content = parts[0];
this.content.setContainer(this.container);
this.content.render();
}
}, },
position() { position() {
var items; var items;
if (this.anchorStart()) { if (this.contents) {
if (this.contents.anchor_start) {
this.positionLabel(this.contents.anchor_start); this.positionLabel(this.contents.anchor_start);
} }
if (this.anchorEnd()) { if (this.contents.anchor_end) {
this.positionLabel(this.contents.anchor_end); this.positionLabel(this.contents.anchor_end);
} }
@ -41,6 +50,9 @@ export default _.extend({}, Base, {
this.spaceHorizontally(items, { this.spaceHorizontally(items, {
padding: 10 padding: 10
}); });
} else {
this.content.position();
}
}, },
anchorStart() { anchorStart() {

View File

@ -5,7 +5,11 @@ export default _.extend({}, Base, {
type: 'match-fragment', type: 'match-fragment',
render() { render() {
if (this._repeat.textValue === '') {
this._content.setContainer(this.container);
} else {
this._content.setContainer(this.container.group()); this._content.setContainer(this.container.group());
}
this._content.render(); this._content.render();
}, },

View File

@ -5,13 +5,21 @@ export default _.extend({}, Base, {
type: 'regexp', type: 'regexp',
render() { render() {
this.matchContainer = this.container.group(); var matches = this.matches();
_.each(this.matches(), (match => { if (matches.length === 1) {
matches[0].setContainer(this.container);
matches[0].render();
} else {
this.matchContainer = this.container.group()
.addClass('regexp-matches');
_.each(matches, (match => {
match.setContainer(this.matchContainer.group()); match.setContainer(this.matchContainer.group());
match.render(); match.render();
return match.container; return match.container;
}).bind(this)); }).bind(this));
}
}, },
position() { position() {
@ -22,11 +30,11 @@ export default _.extend({}, Base, {
_.invoke(matches, 'position'); _.invoke(matches, 'position');
if (includeLines) {
this.spaceVertically(matches, { this.spaceVertically(matches, {
padding: 5 padding: 5
}); });
if (includeLines) {
this.matchContainer.transform(Snap.matrix() this.matchContainer.transform(Snap.matrix()
.translate(20, 0)); .translate(20, 0));