Simplifying node proxy code

This commit is contained in:
Jeff Avallone 2014-12-17 15:12:04 -05:00
parent dd6eac2b4e
commit c5c98ad62f
5 changed files with 120 additions and 123 deletions

View File

@ -18,7 +18,6 @@ export default {
.invoke('addClass', 'anchor'); .invoke('addClass', 'anchor');
} }
if (start || end || this.parts.length !== 1) {
partPromises = _.map(this.parts, part => { partPromises = _.map(this.parts, part => {
return part.render(this.container.group()); return part.render(this.container.group());
}); });
@ -46,9 +45,6 @@ export default {
this.container.prepend( this.container.prepend(
this.container.path(paths.join(''))); this.container.path(paths.join('')));
}); });
} else {
return this.proxy(this.parts[0]);
}
}, },
_getAnchor() { _getAnchor() {
@ -79,5 +75,9 @@ export default {
this.anchorStart = this.properties.anchor_start.textValue !== ''; this.anchorStart = this.properties.anchor_start.textValue !== '';
this.anchorEnd = this.properties.anchor_end.textValue !== ''; this.anchorEnd = this.properties.anchor_end.textValue !== '';
if (!this.anchorStart && !this.anchorEnd && this.parts.length === 1) {
this.proxy = this.parts[0];
}
} }
}; };

View File

@ -4,9 +4,6 @@ export default {
type: 'match-fragment', type: 'match-fragment',
_render() { _render() {
if (!this.repeat) {
return this.proxy(this.content);
} else {
return this.content.render(this.container.group()) return this.content.render(this.container.group())
.then(() => { .then(() => {
var box, paths = []; var box, paths = [];
@ -56,7 +53,6 @@ export default {
.translate(box.x2 - labelBox.width - labelShift, box.y2 + labelBox.height)); .translate(box.x2 - labelBox.width - labelShift, box.y2 + labelBox.height));
} }
}); });
}
}, },
_getAnchor() { _getAnchor() {
@ -76,6 +72,8 @@ export default {
if (this.properties.repeat.textValue !== '') { if (this.properties.repeat.textValue !== '') {
this.repeat = this.properties.repeat; this.repeat = this.properties.repeat;
} else {
this.proxy = this.content;
} }
} }
}; };

View File

@ -26,8 +26,8 @@ export default class Node {
} }
getAnchor() { getAnchor() {
if (this._proxy) { if (this.proxy) {
return this._proxy.getAnchor(); return this.proxy.getAnchor();
} else { } else {
return this._getAnchor(); return this._getAnchor();
} }
@ -119,16 +119,15 @@ export default class Node {
this.setContainer(container); this.setContainer(container);
} }
if (this.proxy) {
return this.proxy.render(this.container)
.then(_.constant(this));
} else {
this.startRender(); this.startRender();
return this._render() return this._render()
.then(this.doneRender.bind(this)) .then(this.doneRender.bind(this))
.then(_.constant(this)); .then(_.constant(this));
} }
proxy(node) {
this.anchorDebug = false;
this._proxy = node;
return node.render(this.container);
} }
spaceHorizontally(items, options) { spaceHorizontally(items, options) {

View File

@ -7,9 +7,6 @@ export default {
_render() { _render() {
var matchContainer; var matchContainer;
if (this.matches.length === 1) {
return this.proxy(this.matches[0]);
} else {
matchContainer = this.container.group() matchContainer = this.container.group()
.addClass('regexp-matches') .addClass('regexp-matches')
.transform(Snap.matrix() .transform(Snap.matrix()
@ -43,7 +40,6 @@ export default {
return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${container.width}`; return `M0,${box.ay}h${box.ax}M${box.ax2},${box.ay}H${container.width}`;
}).join(''))); }).join('')));
}); });
}
}, },
makeSideLine(containerBox, match) { makeSideLine(containerBox, match) {
@ -91,5 +87,9 @@ export default {
.concat(_.map(this.properties.alternates.elements, element => { .concat(_.map(this.properties.alternates.elements, element => {
return element.properties.match; return element.properties.match;
})); }));
if (this.matches.length === 1) {
return this.proxy = this.matches[0];
}
} }
}; };

View File

@ -12,14 +12,10 @@ export default {
}, },
_render() { _render() {
if (this.label) {
return this.regexp.render(this.container.group()) return this.regexp.render(this.container.group())
.then(this.renderLabeledBox.bind(this, this.label, this.regexp, { .then(this.renderLabeledBox.bind(this, this.label, this.regexp, {
padding: 10 padding: 10
})); }));
} else {
return this.proxy(this.regexp);
}
}, },
resetCounter() { resetCounter() {
@ -45,5 +41,9 @@ export default {
} }
this.regexp = this.properties.regexp; this.regexp = this.properties.regexp;
if (!this.label) {
this.proxy = this.regexp;
}
} }
}; };