Replacing Q promises with ES6 promises

This commit is contained in:
Jeff Avallone
2015-03-14 17:11:14 -04:00
parent 3970224302
commit 0093db8e20
24 changed files with 212 additions and 254 deletions
+1 -2
View File
@@ -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 -2
View File
@@ -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())
])
+2 -1
View File
@@ -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;
});
},
+3 -1
View File
@@ -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;
});
},
+7 -4
View File
@@ -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);
+9 -13
View File
@@ -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 -2
View File
@@ -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(() => {