Further refactoring of Regexper class
Still not entirely sure this is setup how I'd like it to be.
This commit is contained in:
parent
ae064b2b8e
commit
cd279d3a80
@ -41,7 +41,8 @@ export default class Regexper {
|
|||||||
.then((() => {
|
.then((() => {
|
||||||
this.setState('has-results');
|
this.setState('has-results');
|
||||||
this.updateLinks();
|
this.updateLinks();
|
||||||
}).bind(this), this.showError.bind(this));
|
}).bind(this))
|
||||||
|
.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +65,8 @@ export default class Regexper {
|
|||||||
this.setState('has-error');
|
this.setState('has-error');
|
||||||
this.error.innerHTML = '';
|
this.error.innerHTML = '';
|
||||||
this.error.appendChild(document.createTextNode(message));
|
this.error.appendChild(document.createTextNode(message));
|
||||||
|
|
||||||
|
throw message;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLinks() {
|
updateLinks() {
|
||||||
@ -76,49 +79,32 @@ export default class Regexper {
|
|||||||
this.permalink.setAttribute('href', location);
|
this.permalink.setAttribute('href', location);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSvg(snap, expression) {
|
renderRegexp(expression) {
|
||||||
var deferred = Q.defer(),
|
var snap = Snap(this.svg),
|
||||||
|
deferred = Q.defer(),
|
||||||
|
padding = this.padding,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
snap.selectAll('g').remove();
|
snap.selectAll('g').remove();
|
||||||
|
|
||||||
setTimeout(() => {
|
return Q.fcall(parser.parse.bind(parser), expression)
|
||||||
try {
|
.then((result) => {
|
||||||
result = parser.parse(expression);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
deferred.reject(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
result.container = snap.group();
|
result.container = snap.group();
|
||||||
result.render();
|
result.render();
|
||||||
deferred.resolve(result);
|
return result;
|
||||||
}
|
}, this.showError.bind(this))
|
||||||
});
|
.then((result) => {
|
||||||
|
var box;
|
||||||
|
|
||||||
return deferred.promise;
|
result.position();
|
||||||
}
|
|
||||||
|
|
||||||
positionSvg(snap, parsed) {
|
box = result.container.getBBox();
|
||||||
var box;
|
result.container.transform(Snap.matrix()
|
||||||
|
.translate(padding - box.x, padding - box.y));
|
||||||
parsed.position();
|
snap.attr({
|
||||||
|
width: box.width + padding * 2,
|
||||||
box = parsed.container.getBBox();
|
height: box.height + padding * 2
|
||||||
parsed.container.transform(Snap.matrix()
|
});
|
||||||
.translate(this.padding - box.x, this.padding - box.y));
|
});
|
||||||
snap.attr({
|
|
||||||
width: box.width + this.padding * 2,
|
|
||||||
height: box.height + this.padding * 2
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
renderRegexp(expression) {
|
|
||||||
var padding = this.padding,
|
|
||||||
snap = Snap(this.svg);
|
|
||||||
|
|
||||||
return this.renderSvg(snap, expression)
|
|
||||||
.then(this.positionSvg.bind(this, snap));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user