Creating helper methods for the setTimeout uses
Abstracting out some of the setTimeout patterns that have popped up in the code to make the intention clearer.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Snap from 'snapsvg';
|
||||
import _ from 'lodash';
|
||||
|
||||
import util from '../util.js';
|
||||
import javascript from './javascript/parser.js';
|
||||
import ParserState from './javascript/parser_state.js';
|
||||
|
||||
@@ -46,18 +47,11 @@ export default class Parser {
|
||||
parse(expression) {
|
||||
this._addClass('loading');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
return util.tick().then(() => {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
resolve(this);
|
||||
}
|
||||
catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -57,15 +57,13 @@ export default class Node {
|
||||
return this.container.transform(matrix);
|
||||
}
|
||||
|
||||
deferredStep() {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (this.state.cancelRender) {
|
||||
reject('Render cancelled');
|
||||
} else {
|
||||
resolve.apply(this, arguments);
|
||||
}
|
||||
}, 1);
|
||||
deferredStep(value) {
|
||||
return util.tick().then(() => {
|
||||
if (this.state.cancelRender) {
|
||||
throw 'Render cancelled';
|
||||
}
|
||||
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user