Folding _position methods into render method promises

This commit is contained in:
Jeff Avallone 2014-12-13 12:55:03 -05:00
parent 29316bb2aa
commit cb9785de91
8 changed files with 130 additions and 140 deletions

View File

@ -47,9 +47,6 @@ export default {
}
var promise = this._render();
if (!this._proxy) {
promise = promise.then(this._position.bind(this));
}
return promise.then(_.constant(this));
},
@ -71,8 +68,6 @@ export default {
});
},
_position() {},
spaceHorizontally(items, options) {
var verticalCenter = 0;

View File

@ -6,23 +6,24 @@ export default _.extend({}, Base, {
type: 'charset',
_render() {
var partContainer;
this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:');
this.partContainer = this.container.group();
partContainer = this.container.group();
return Q.all(_.map(this.parts.elements, (part => {
return part.render(this.partContainer.group());
}).bind(this)));
},
_position() {
return Q.all(_.map(this.parts.elements, part => {
return part.render(partContainer.group());
}))
.then((() => {
this.spaceVertically(this.parts.elements, {
padding: 5
});
this.positionLabeledBox(this.partContainer, {
this.positionLabeledBox(partContainer, {
padding: 5
});
}).bind(this));
},
invert() {

View File

@ -6,7 +6,7 @@ export default _.extend({}, Base, {
type: 'charset-range',
_render() {
this.hyphen = this.container.text()
var hyphen = this.container.text()
.attr({
text: '-'
});
@ -14,12 +14,11 @@ export default _.extend({}, Base, {
return Q.all([
this.first.render(this.container.group()),
this.last.render(this.container.group())
]);
},
_position() {
this.spaceHorizontally([this.first, this.hyphen, this.last], {
])
.then((() => {
this.spaceHorizontally([this.first, hyphen, this.last], {
padding: 5
});
}).bind(this));
}
});

View File

@ -27,16 +27,15 @@ export default _.extend({}, Base, {
return part.render(this.container.group());
}).bind(this));
return Q.all(_([start, partPromises, end]).flatten().compact().value());
} else {
return this.proxy(parts[0]);
}
},
_position(items) {
return Q.all(_([start, partPromises, end]).flatten().compact().value())
.then(((items) => {
this.spaceHorizontally(items, {
padding: 10
});
}).bind(this));
} else {
return this.proxy(parts[0]);
}
},
anchorStart() {

View File

@ -8,11 +8,8 @@ export default _.extend({}, Base, {
if (this._repeat.textValue === '') {
return this.proxy(this._content);
} else {
return this._content.render(this.container.group());
}
},
_position() {
return this._content.render(this.container.group())
.then((() => {
var box, paths = [];
this._content.transform(this._repeat.contentPosition());
@ -38,5 +35,7 @@ export default _.extend({}, Base, {
this.container.prepend(
this.container.path(paths.join('')));
}
}).bind(this));
}
}
});

View File

@ -6,32 +6,28 @@ export default _.extend({}, Base, {
type: 'regexp',
_render() {
var matches = this.matches();
var matches = this.matches(),
matchContainer;
if (matches.length === 1) {
return this.proxy(matches[0]);
} else {
this.matchContainer = this.container.group()
.addClass('regexp-matches');
matchContainer = this.container.group()
.addClass('regexp-matches')
.transform(Snap.matrix()
.translate(20, 0));
return Q.all(_.map(matches, (match => {
return match.render(this.matchContainer.group());
}).bind(this)));
}
},
_position() {
var matches = this.matches(),
containerBox,
return Q.all(_.map(matches, match => {
return match.render(matchContainer.group());
}))
.then((() => {
var containerBox,
paths;
this.spaceVertically(matches, {
padding: 5
});
this.matchContainer.transform(Snap.matrix()
.translate(20, 0));
containerBox = this.getBBox();
paths = _.map(matches, match => {
var box = match.getBBox(),
@ -76,6 +72,8 @@ export default _.extend({}, Base, {
this.container.prepend(
this.container.path(paths.join('')));
}).bind(this));
}
},
matches() {

View File

@ -5,10 +5,6 @@ export default _.extend({}, Base, {
type: 'root',
_render() {
var promise = this.regexp.render(this.container.group());
this.regexp.transform(Snap.matrix()
.translate(10, 0));
this.start = this.container.circle()
.addClass('pin')
.attr({ r: 5 });
@ -16,16 +12,20 @@ export default _.extend({}, Base, {
.addClass('pin')
.attr({ r: 5 });
return promise;
},
return this.regexp.render(this.container.group())
.then((() => {
var contentBox;
_position() {
var contentBox = this.regexp.getBBox();
this.regexp.transform(Snap.matrix()
.translate(10, 0));
contentBox = this.regexp.getBBox();
this.start.transform(Snap.matrix()
.translate(0, contentBox.cy));
this.end.transform(Snap.matrix()
.translate(contentBox.x2 + 10, contentBox.cy));
}).bind(this));
},
flags() {

View File

@ -18,16 +18,15 @@ export default _.extend({}, Base, {
if (label) {
this.renderLabeledBox(label);
return this.regexp.render(this.container.group());
} else {
return this.proxy(this.regexp);
}
},
_position() {
return this.regexp.render(this.container.group())
.then((() => {
this.positionLabeledBox(this.regexp, {
padding: 10
});
}).bind(this));
} else {
return this.proxy(this.regexp);
}
},
groupLabel() {