From 00e84c72bc850d7c3a3bd667035f54f894a9437d Mon Sep 17 00:00:00 2001 From: Ivan Borzenkov Date: Fri, 5 Jan 2024 21:30:53 +0300 Subject: [PATCH] replace Q to Promise --- src/app/app.js | 16 ++++++------ src/app/bootstrap.js | 33 +++++++++++------------- src/app/lib/models/generic_collection.js | 7 ++--- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/app/app.js b/src/app/app.js index 10e1ba7fc8..572c2b896f 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -176,15 +176,15 @@ var initTemplates = function () { var ts = []; _.each(document.querySelectorAll('[type="text/x-template"]'), function (el) { - var d = Q.defer(); - $.get(el.src, function (res) { - el.innerHTML = res; - d.resolve(true); - }); - ts.push(d.promise); + ts.push(new Promise((resolve, reject) => { + $.get(el.src, function (res) { + el.innerHTML = res; + resolve(true); + }); + })); }); - return Q.all(ts); + return Promise.all(ts); }; var initApp = function () { @@ -544,7 +544,7 @@ var handleVideoFile = function (file) { // get subtitles from provider var getSubtitles = function (subdata) { - return Q.Promise(function (resolve, reject) { + return new Promise(function (resolve, reject) { win.debug('Subtitles data request:', subdata); var subtitleProvider = App.Config.getProviderForType('subtitle'); diff --git a/src/app/bootstrap.js b/src/app/bootstrap.js index c5e9529551..bda0764eb8 100644 --- a/src/app/bootstrap.js +++ b/src/app/bootstrap.js @@ -7,11 +7,11 @@ var fs = require('fs'); function loadLocalProviders() { - var appPath = ''; var providerPath = './src/app/lib/providers/'; var files = fs.readdirSync(providerPath); + var head = document.getElementsByTagName('head')[0]; return files .map(function(file) { if (!file.match(/\.js$/) || file.match(/generic.js$/)) { @@ -20,23 +20,20 @@ win.info('loading local provider', file); - var q = Q.defer(); + return new Promise((resolve, reject) => { + var script = document.createElement('script'); - var head = document.getElementsByTagName('head')[0]; - var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = 'lib/providers/' + file; - script.type = 'text/javascript'; - script.src = 'lib/providers/' + file; - - script.onload = function() { - this.onload = null; - win.info('loaded', file); - q.resolve(file); - }; - - head.appendChild(script); + script.onload = function() { + script.onload = null; + win.info('loaded', file); + resolve(file); + }; - return q.promise; + head.appendChild(script); + }); }) .filter(function(q) { return q; @@ -75,7 +72,7 @@ } function loadNpmSettings() { - return Q.all( + return Promise.all( loadFromPackageJSON(/butter-settings-/, function(settings) { Settings = _.extend(Settings, settings); }) @@ -83,13 +80,13 @@ } function loadProviders() { - return Q.all( + return Promise.all( loadLocalProviders() ); } function loadProvidersDelayed() { - return Q.all( + return Promise.all( loadNpmProviders().concat(loadLegacyNpmProviders()) ); } diff --git a/src/app/lib/models/generic_collection.js b/src/app/lib/models/generic_collection.js index 78e07b6bf5..00fee6bd91 100644 --- a/src/app/lib/models/generic_collection.js +++ b/src/app/lib/models/generic_collection.js @@ -2,9 +2,8 @@ 'use strict'; var getDataFromProvider = function (providers, collection) { - var deferred = Q.defer(); var filters = Object.assign(collection.filter, {page: providers.torrent.page}); - providers.torrent.fetch(filters) + return providers.torrent.fetch(filters) .then(function (torrents) { // If a new request was started... _.each(torrents.results, function (movie) { @@ -25,14 +24,12 @@ movie.providers = providers; }); - return deferred.resolve(torrents); + return torrents; }) .catch(function (err) { collection.state = 'error'; collection.trigger('loaded', collection, collection.state); }); - - return deferred.promise; }; var PopCollection = Backbone.Collection.extend({