Replacing Q promises with ES6 promises
This commit is contained in:
+12
-15
@@ -1,4 +1,3 @@
|
||||
import Q from 'q';
|
||||
import Snap from 'snapsvg';
|
||||
import _ from 'lodash';
|
||||
|
||||
@@ -45,23 +44,21 @@ export default class Parser {
|
||||
}
|
||||
|
||||
parse(expression) {
|
||||
var deferred = Q.defer();
|
||||
|
||||
this._addClass('loading');
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
deferred.resolve(this);
|
||||
}
|
||||
catch(e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
resolve(this);
|
||||
}
|
||||
catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -78,7 +75,7 @@ export default class Parser {
|
||||
height: box.height + 20
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
.then(() => {
|
||||
this._removeClass('loading');
|
||||
this.container.removeChild(this.container.querySelector('.progress'));
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
export default {
|
||||
type: 'charset',
|
||||
|
||||
@@ -22,7 +21,7 @@ export default {
|
||||
_render() {
|
||||
this.partContainer = this.container.group();
|
||||
|
||||
return Q.all(_.map(this.elements, part => {
|
||||
return Promise.all(_.map(this.elements, part => {
|
||||
return part.render(this.partContainer.group());
|
||||
}))
|
||||
.then(() => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
export default {
|
||||
type: 'charset-range',
|
||||
@@ -12,7 +11,7 @@ export default {
|
||||
this.last
|
||||
];
|
||||
|
||||
return Q.all([
|
||||
return Promise.all([
|
||||
this.first.render(this.container.group()),
|
||||
this.last.render(this.container.group())
|
||||
])
|
||||
|
||||
@@ -15,11 +15,12 @@ export default {
|
||||
|
||||
_render() {
|
||||
return this.renderLabel(this.label)
|
||||
.tap(label => {
|
||||
.then(label => {
|
||||
label.select('rect').attr({
|
||||
rx: 3,
|
||||
ry: 3
|
||||
});
|
||||
return label;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export default {
|
||||
|
||||
_render() {
|
||||
return this.renderLabel(['\u201c', this.literal, '\u201d'])
|
||||
.tap(label => {
|
||||
.then(label => {
|
||||
var spans = label.selectAll('tspan');
|
||||
|
||||
spans[0].addClass('quote');
|
||||
@@ -15,6 +15,8 @@ export default {
|
||||
rx: 3,
|
||||
ry: 3
|
||||
});
|
||||
|
||||
return label;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
export default {
|
||||
type: 'match',
|
||||
@@ -28,12 +27,16 @@ export default {
|
||||
|
||||
if (this.anchorStart) {
|
||||
start = this.renderLabel('Start of line')
|
||||
.invoke('addClass', 'anchor');
|
||||
.then(label => {
|
||||
return label.addClass('anchor');
|
||||
});
|
||||
}
|
||||
|
||||
if (this.anchorEnd) {
|
||||
end = this.renderLabel('End of line')
|
||||
.invoke('addClass', 'anchor');
|
||||
.then(label => {
|
||||
return label.addClass('anchor');
|
||||
});
|
||||
}
|
||||
|
||||
partPromises = _.map(this.parts, part => {
|
||||
@@ -46,7 +49,7 @@ export default {
|
||||
items = [this.container.group()];
|
||||
}
|
||||
|
||||
return Q.all(items)
|
||||
return Promise.all(items)
|
||||
.then(items => {
|
||||
this.start = _.first(items);
|
||||
this.end = _.last(items);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
export default class Node {
|
||||
constructor(textValue, offset, elements, properties) {
|
||||
@@ -59,18 +58,15 @@ export default class Node {
|
||||
}
|
||||
|
||||
deferredStep() {
|
||||
var deferred = Q.defer(),
|
||||
result = arguments;
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.state.cancelRender) {
|
||||
deferred.reject('Render cancelled');
|
||||
} else {
|
||||
deferred.resolve.apply(this, result);
|
||||
}
|
||||
}, 1);
|
||||
|
||||
return deferred.promise;
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (this.state.cancelRender) {
|
||||
reject('Render cancelled');
|
||||
} else {
|
||||
resolve.apply(this, arguments);
|
||||
}
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
|
||||
renderLabel(text) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import util from '../../util.js';
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
export default {
|
||||
type: 'regexp',
|
||||
@@ -11,7 +10,7 @@ export default {
|
||||
.transform(Snap.matrix()
|
||||
.translate(20, 0));
|
||||
|
||||
return Q.all(_.map(this.matches, match => {
|
||||
return Promise.all(_.map(this.matches, match => {
|
||||
return match.render(matchContainer.group());
|
||||
}))
|
||||
.then(() => {
|
||||
|
||||
Reference in New Issue
Block a user