Skip to content

Commit 00e84c7

Browse files
committed
replace Q to Promise
1 parent a13069b commit 00e84c7

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

src/app/app.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ var initTemplates = function () {
176176
var ts = [];
177177

178178
_.each(document.querySelectorAll('[type="text/x-template"]'), function (el) {
179-
var d = Q.defer();
180-
$.get(el.src, function (res) {
181-
el.innerHTML = res;
182-
d.resolve(true);
183-
});
184-
ts.push(d.promise);
179+
ts.push(new Promise((resolve, reject) => {
180+
$.get(el.src, function (res) {
181+
el.innerHTML = res;
182+
resolve(true);
183+
});
184+
}));
185185
});
186186

187-
return Q.all(ts);
187+
return Promise.all(ts);
188188
};
189189

190190
var initApp = function () {
@@ -544,7 +544,7 @@ var handleVideoFile = function (file) {
544544

545545
// get subtitles from provider
546546
var getSubtitles = function (subdata) {
547-
return Q.Promise(function (resolve, reject) {
547+
return new Promise(function (resolve, reject) {
548548
win.debug('Subtitles data request:', subdata);
549549

550550
var subtitleProvider = App.Config.getProviderForType('subtitle');

src/app/bootstrap.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
var fs = require('fs');
88

99
function loadLocalProviders() {
10-
var appPath = '';
1110
var providerPath = './src/app/lib/providers/';
1211

1312
var files = fs.readdirSync(providerPath);
1413

14+
var head = document.getElementsByTagName('head')[0];
1515
return files
1616
.map(function(file) {
1717
if (!file.match(/\.js$/) || file.match(/generic.js$/)) {
@@ -20,23 +20,20 @@
2020

2121
win.info('loading local provider', file);
2222

23-
var q = Q.defer();
23+
return new Promise((resolve, reject) => {
24+
var script = document.createElement('script');
2425

25-
var head = document.getElementsByTagName('head')[0];
26-
var script = document.createElement('script');
26+
script.type = 'text/javascript';
27+
script.src = 'lib/providers/' + file;
2728

28-
script.type = 'text/javascript';
29-
script.src = 'lib/providers/' + file;
30-
31-
script.onload = function() {
32-
this.onload = null;
33-
win.info('loaded', file);
34-
q.resolve(file);
35-
};
36-
37-
head.appendChild(script);
29+
script.onload = function() {
30+
script.onload = null;
31+
win.info('loaded', file);
32+
resolve(file);
33+
};
3834

39-
return q.promise;
35+
head.appendChild(script);
36+
});
4037
})
4138
.filter(function(q) {
4239
return q;
@@ -75,21 +72,21 @@
7572
}
7673

7774
function loadNpmSettings() {
78-
return Q.all(
75+
return Promise.all(
7976
loadFromPackageJSON(/butter-settings-/, function(settings) {
8077
Settings = _.extend(Settings, settings);
8178
})
8279
);
8380
}
8481

8582
function loadProviders() {
86-
return Q.all(
83+
return Promise.all(
8784
loadLocalProviders()
8885
);
8986
}
9087

9188
function loadProvidersDelayed() {
92-
return Q.all(
89+
return Promise.all(
9390
loadNpmProviders().concat(loadLegacyNpmProviders())
9491
);
9592
}

src/app/lib/models/generic_collection.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
'use strict';
33

44
var getDataFromProvider = function (providers, collection) {
5-
var deferred = Q.defer();
65
var filters = Object.assign(collection.filter, {page: providers.torrent.page});
7-
providers.torrent.fetch(filters)
6+
return providers.torrent.fetch(filters)
87
.then(function (torrents) {
98
// If a new request was started...
109
_.each(torrents.results, function (movie) {
@@ -25,14 +24,12 @@
2524
movie.providers = providers;
2625
});
2726

28-
return deferred.resolve(torrents);
27+
return torrents;
2928
})
3029
.catch(function (err) {
3130
collection.state = 'error';
3231
collection.trigger('loaded', collection, collection.state);
3332
});
34-
35-
return deferred.promise;
3633
};
3734

3835
var PopCollection = Backbone.Collection.extend({

0 commit comments

Comments
 (0)