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');
}
if (start || end || this.parts.length !== 1) {
partPromises = _.map(this.parts, part => {
return part.render(this.container.group());
});
@ -46,9 +45,6 @@ export default {
this.container.prepend(
this.container.path(paths.join('')));
});
} else {
return this.proxy(this.parts[0]);
}
},
_getAnchor() {
@ -79,5 +75,9 @@ export default {
this.anchorStart = this.properties.anchor_start.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',
_render() {
if (!this.repeat) {
return this.proxy(this.content);
} else {
return this.content.render(this.container.group())
.then(() => {
var box, paths = [];
@ -56,7 +53,6 @@ export default {
.translate(box.x2 - labelBox.width - labelShift, box.y2 + labelBox.height));
}
});
}
},
_getAnchor() {
@ -76,6 +72,8 @@ export default {
if (this.properties.repeat.textValue !== '') {
this.repeat = this.properties.repeat;
} else {
this.proxy = this.content;
}
}
};

View File

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

View File

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

View File

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