Refactoring rendering code to allow the loader to show

The loader is mostly an easter egg for people who like to try rendering
that enormous email-matching regexp from the Mail::RFC822::Address perl
module
This commit is contained in:
Jeff Avallone 2014-12-07 18:19:00 -05:00
parent e99c284216
commit 52a0863449

View File

@ -69,7 +69,7 @@ export default class Regexper {
updateLinks() {
var blob, url;
blob = new Blob([svg.outerHTML], { type: 'image/svg+xml' });
blob = new Blob([this.svg.outerHTML], { type: 'image/svg+xml' });
url = URL.createObjectURL(blob);
this.download.setAttribute('href', url);
@ -77,15 +77,27 @@ export default class Regexper {
}
renderSvg(snap, expression) {
var result;
var deferred = Q.defer(),
result;
snap.selectAll('g').remove();
setTimeout(() => {
try {
result = parser.parse(expression);
}
catch(e) {
deferred.reject(e);
}
if (result) {
result.container = snap.group();
result.render();
deferred.resolve(result);
}
});
return result;
return deferred.promise;
}
positionSvg(snap, parsed) {
@ -104,15 +116,9 @@ export default class Regexper {
renderRegexp(expression) {
var padding = this.padding,
snap = Snap(this.svg),
promise;
snap = Snap(this.svg);
promise = Q.promise(((resolve, reject, notify) => {
resolve(this.renderSvg(snap, expression));
}).bind(this));
promise.then(this.positionSvg.bind(this, snap));
return promise;
return this.renderSvg(snap, expression)
.then(this.positionSvg.bind(this, snap));
}
}