regexper-static/src/js/parser/javascript/match_fragment.js
Jeff Avallone 773fd5c1a6 Refactoring how _position is called to be promise-based
The render method now returns a promise. Once this promise is resolved,
the _position method for that node will be called (if applicable). This
promise must be resolved only after all subordinate nodes have completed
their render phase (the promise returned by subordinate node's render
method has resolved). Node that do not have subordinates can return the
result of calling terminalRender, and proxied renders only need to
return the result of calling proxy.

With this change, it is no longer necessary to explicitly position
subordinate nodes. They will already be positioned once their render
promise is resolved.
2014-12-13 09:09:58 -05:00

43 lines
1.0 KiB
JavaScript

import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
type: 'match-fragment',
_render() {
if (this._repeat.textValue === '') {
return this.proxy(this._content);
} else {
return this._content.render(this.container.group());
}
},
_position() {
var box, paths = [];
this._content.transform(this._repeat.contentPosition());
box = this._content.getBBox();
if (this._repeat.hasSkip()) {
paths.push(Snap.format('M0,{box.cy}q10,0 10,-10v-{vert}q0,-10 10,-10h{horiz}q10,0 10,10v{vert}q0,10 10,10', {
box,
vert: box.height / 2 - 10,
horiz: box.width - 10
}));
}
if (this._repeat.hasLoop()) {
paths.push(Snap.format('M{box.x},{box.cy}q-10,0 -10,10v{vert}q0,10 10,10h{box.width}q10,0 10,-10v-{vert}q0,-10 -10,-10', {
box,
vert: box.height / 2 - 10
}));
}
if (paths.length) {
this.container.prepend(
this.container.path(paths.join('')));
}
}
});