diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-06-19 11:43:12 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-06-19 11:43:12 +0200 |
commit | d84b169e75bbf0e4f1888e8d5287323bb3ed61da (patch) | |
tree | 90c04201734dea68283f0a6bdd5ff03153f641ee /application/palemoon/base/content/newtab/updater.js | |
parent | e7b69b29df1593be14ce7c6efdad2f2c973a1c01 (diff) | |
download | UXP-d84b169e75bbf0e4f1888e8d5287323bb3ed61da.tar UXP-d84b169e75bbf0e4f1888e8d5287323bb3ed61da.tar.gz UXP-d84b169e75bbf0e4f1888e8d5287323bb3ed61da.tar.lz UXP-d84b169e75bbf0e4f1888e8d5287323bb3ed61da.tar.xz UXP-d84b169e75bbf0e4f1888e8d5287323bb3ed61da.zip |
Stop using old-style promises module in about:newtab.
- Rewrite to arrow functions.
- Stop using .defer and .promised
Tag #517.
Diffstat (limited to 'application/palemoon/base/content/newtab/updater.js')
-rw-r--r-- | application/palemoon/base/content/newtab/updater.js | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/application/palemoon/base/content/newtab/updater.js b/application/palemoon/base/content/newtab/updater.js index e6da37f87..2bab74d70 100644 --- a/application/palemoon/base/content/newtab/updater.js +++ b/application/palemoon/base/content/newtab/updater.js @@ -20,24 +20,22 @@ var gUpdater = { // Find all sites that remain in the grid. let sites = this._findRemainingSites(links); - let self = this; - // Remove sites that are no longer in the grid. - this._removeLegacySites(sites, function () { + this._removeLegacySites(sites, () => { // Freeze all site positions so that we can move their DOM nodes around // without any visual impact. - self._freezeSitePositions(sites); + this._freezeSitePositions(sites); // Move the sites' DOM nodes to their new position in the DOM. This will // have no visual effect as all the sites have been frozen and will // remain in their current position. - self._moveSiteNodes(sites); + this._moveSiteNodes(sites); // Now it's time to animate the sites actually moving to their new // positions. - self._rearrangeSites(sites, function () { + this._rearrangeSites(sites, () => { // Try to fill empty cells and finish. - self._fillEmptyCells(links, aCallback); + this._fillEmptyCells(links, aCallback); // Update other pages that might be open to keep them synced. gAllPages.update(gPage); @@ -134,21 +132,19 @@ var gUpdater = { if (!aSite || aSites.indexOf(aSite) != -1) return; - let deferred = Promise.defer(); - batch.push(deferred.promise); - - // Fade out the to-be-removed site. - gTransformation.hideSite(aSite, function () { - let node = aSite.node; + batch.push(new Promise(resolve => { + // Fade out the to-be-removed site. + gTransformation.hideSite(aSite, function () { + let node = aSite.node; - // Remove the site from the DOM. - node.parentNode.removeChild(node); - deferred.resolve(); - }); + // Remove the site from the DOM. + node.parentNode.removeChild(node); + resolve(); + }); + })); }); - let wait = Promise.promised(aCallback); - wait.apply(null, batch); + Promise.all(batch).then(aCallback); }, /** @@ -158,29 +154,24 @@ var gUpdater = { */ _fillEmptyCells: function Updater_fillEmptyCells(aLinks, aCallback) { let {cells, sites} = gGrid; - let batch = []; // Find empty cells and fill them. - sites.forEach(function (aSite, aIndex) { + Promise.all(sites.map((aSite, aIndex) => { if (aSite || !aLinks[aIndex]) - return; - - let deferred = Promise.defer(); - batch.push(deferred.promise); + return null; - // Create the new site and fade it in. - let site = gGrid.createSite(aLinks[aIndex], cells[aIndex]); + return new Promise(resolve => { + // Create the new site and fade it in. + let site = gGrid.createSite(aLinks[aIndex], cells[aIndex]); - // Set the site's initial opacity to zero. - site.node.style.opacity = 0; + // Set the site's initial opacity to zero. + site.node.style.opacity = 0; - // Flush all style changes for the dynamically inserted site to make - // the fade-in transition work. - window.getComputedStyle(site.node).opacity; - gTransformation.showSite(site, function () deferred.resolve()); - }); - - let wait = Promise.promised(aCallback); - wait.apply(null, batch); + // Flush all style changes for the dynamically inserted site to make + // the fade-in transition work. + window.getComputedStyle(site.node).opacity; + gTransformation.showSite(site, resolve); + }); + })).then(aCallback).catch(console.exception); } }; |