mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
Stop using old-style promises module in about:newtab.
- Rewrite to arrow functions. - Stop using .defer and .promised Tag #517.
This commit is contained in:
parent
5c9e19b2cc
commit
d767e24977
3 changed files with 40 additions and 50 deletions
|
|
@ -11,7 +11,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
Cu.import("resource://gre/modules/PageThumbs.jsm");
|
Cu.import("resource://gre/modules/PageThumbs.jsm");
|
||||||
Cu.import("resource://gre/modules/NewTabUtils.jsm");
|
Cu.import("resource://gre/modules/NewTabUtils.jsm");
|
||||||
Cu.import("resource:///modules/promise.js");
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "Rect",
|
XPCOMUtils.defineLazyModuleGetter(this, "Rect",
|
||||||
"resource://gre/modules/Geometry.jsm");
|
"resource://gre/modules/Geometry.jsm");
|
||||||
|
|
|
||||||
|
|
@ -179,23 +179,23 @@ var gTransformation = {
|
||||||
if (!aSite || aSite == gDrag.draggedSite)
|
if (!aSite || aSite == gDrag.draggedSite)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
batch.push(new Promise(resolve => {
|
||||||
batch.push(deferred.promise);
|
if (!cells[aIndex]) {
|
||||||
let cb = function () deferred.resolve();
|
|
||||||
|
|
||||||
if (!cells[aIndex])
|
|
||||||
// The site disappeared from the grid, hide it.
|
// The site disappeared from the grid, hide it.
|
||||||
this.hideSite(aSite, cb);
|
this.hideSite(aSite, resolve);
|
||||||
else if (this._getNodeOpacity(aSite.node) != 1)
|
} else if (this._getNodeOpacity(aSite.node) != 1) {
|
||||||
// The site disappeared before but is now back, show it.
|
// The site disappeared before but is now back, show it.
|
||||||
this.showSite(aSite, cb);
|
this.showSite(aSite, resolve);
|
||||||
else
|
} else {
|
||||||
// The site's position has changed, move it around.
|
// The site's position has changed, move it around.
|
||||||
this._moveSite(aSite, aIndex, {unfreeze: unfreeze, callback: cb});
|
this._moveSite(aSite, aIndex, {unfreeze: unfreeze, callback: resolve});
|
||||||
|
}
|
||||||
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
let wait = Promise.promised(function () callback && callback());
|
if (callback) {
|
||||||
wait.apply(null, batch);
|
Promise.all(batch).then(callback);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -20,24 +20,22 @@ var gUpdater = {
|
||||||
// Find all sites that remain in the grid.
|
// Find all sites that remain in the grid.
|
||||||
let sites = this._findRemainingSites(links);
|
let sites = this._findRemainingSites(links);
|
||||||
|
|
||||||
let self = this;
|
|
||||||
|
|
||||||
// Remove sites that are no longer in the grid.
|
// 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
|
// Freeze all site positions so that we can move their DOM nodes around
|
||||||
// without any visual impact.
|
// without any visual impact.
|
||||||
self._freezeSitePositions(sites);
|
this._freezeSitePositions(sites);
|
||||||
|
|
||||||
// Move the sites' DOM nodes to their new position in the DOM. This will
|
// 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
|
// have no visual effect as all the sites have been frozen and will
|
||||||
// remain in their current position.
|
// remain in their current position.
|
||||||
self._moveSiteNodes(sites);
|
this._moveSiteNodes(sites);
|
||||||
|
|
||||||
// Now it's time to animate the sites actually moving to their new
|
// Now it's time to animate the sites actually moving to their new
|
||||||
// positions.
|
// positions.
|
||||||
self._rearrangeSites(sites, function () {
|
this._rearrangeSites(sites, () => {
|
||||||
// Try to fill empty cells and finish.
|
// 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.
|
// Update other pages that might be open to keep them synced.
|
||||||
gAllPages.update(gPage);
|
gAllPages.update(gPage);
|
||||||
|
|
@ -134,21 +132,19 @@ var gUpdater = {
|
||||||
if (!aSite || aSites.indexOf(aSite) != -1)
|
if (!aSite || aSites.indexOf(aSite) != -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
batch.push(new Promise(resolve => {
|
||||||
batch.push(deferred.promise);
|
// Fade out the to-be-removed site.
|
||||||
|
gTransformation.hideSite(aSite, function () {
|
||||||
|
let node = aSite.node;
|
||||||
|
|
||||||
// Fade out the to-be-removed site.
|
// Remove the site from the DOM.
|
||||||
gTransformation.hideSite(aSite, function () {
|
node.parentNode.removeChild(node);
|
||||||
let node = aSite.node;
|
resolve();
|
||||||
|
});
|
||||||
// Remove the site from the DOM.
|
}));
|
||||||
node.parentNode.removeChild(node);
|
|
||||||
deferred.resolve();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let wait = Promise.promised(aCallback);
|
Promise.all(batch).then(aCallback);
|
||||||
wait.apply(null, batch);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -158,29 +154,24 @@ var gUpdater = {
|
||||||
*/
|
*/
|
||||||
_fillEmptyCells: function Updater_fillEmptyCells(aLinks, aCallback) {
|
_fillEmptyCells: function Updater_fillEmptyCells(aLinks, aCallback) {
|
||||||
let {cells, sites} = gGrid;
|
let {cells, sites} = gGrid;
|
||||||
let batch = [];
|
|
||||||
|
|
||||||
// Find empty cells and fill them.
|
// Find empty cells and fill them.
|
||||||
sites.forEach(function (aSite, aIndex) {
|
Promise.all(sites.map((aSite, aIndex) => {
|
||||||
if (aSite || !aLinks[aIndex])
|
if (aSite || !aLinks[aIndex])
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
let deferred = Promise.defer();
|
return new Promise(resolve => {
|
||||||
batch.push(deferred.promise);
|
// Create the new site and fade it in.
|
||||||
|
let site = gGrid.createSite(aLinks[aIndex], cells[aIndex]);
|
||||||
|
|
||||||
// Create the new site and fade it in.
|
// Set the site's initial opacity to zero.
|
||||||
let site = gGrid.createSite(aLinks[aIndex], cells[aIndex]);
|
site.node.style.opacity = 0;
|
||||||
|
|
||||||
// Set the site's initial opacity to zero.
|
// Flush all style changes for the dynamically inserted site to make
|
||||||
site.node.style.opacity = 0;
|
// the fade-in transition work.
|
||||||
|
window.getComputedStyle(site.node).opacity;
|
||||||
// Flush all style changes for the dynamically inserted site to make
|
gTransformation.showSite(site, resolve);
|
||||||
// the fade-in transition work.
|
});
|
||||||
window.getComputedStyle(site.node).opacity;
|
})).then(aCallback).catch(console.exception);
|
||||||
gTransformation.showSite(site, function () deferred.resolve());
|
|
||||||
});
|
|
||||||
|
|
||||||
let wait = Promise.promised(aCallback);
|
|
||||||
wait.apply(null, batch);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue