Remove window id lookup by using a map

This commit is contained in:
Jonathan Kingston 2017-02-16 17:10:02 +00:00
parent 2d6aa70550
commit 2e6f707595

View file

@ -55,7 +55,7 @@ const windowUtils = require("sdk/window/utils");
const ContainerService = { const ContainerService = {
_identitiesState: {}, _identitiesState: {},
_windowMap: {}, _windowMap: new Map(),
init(installation) { init(installation) {
// If we are just been installed, we must store some information for the // If we are just been installed, we must store some information for the
@ -753,17 +753,15 @@ const ContainerService = {
}, },
closeWindow(window) { closeWindow(window) {
const id = windowUtils.getInnerId(window); this._windowMap.delete(window);
delete this._windowMap[id];
}, },
_getOrCreateContainerWindow(window) { _getOrCreateContainerWindow(window) {
const id = windowUtils.getInnerId(window); if (!(this._windowMap.has(window))) {
if (!(id in this._windowMap)) { this._windowMap.set(window, new ContainerWindow(window));
this._windowMap[id] = new ContainerWindow(window);
} }
return this._windowMap[id]; return this._windowMap.get(window);
}, },
_refreshNeeded() { _refreshNeeded() {
@ -771,8 +769,8 @@ const ContainerService = {
}, },
_hideAllPanels() { _hideAllPanels() {
for (let id in this._windowMap) { // eslint-disable-line prefer-const for (let windowObject of this._windowMap.values()) { // eslint-disable-line prefer-const
this._windowMap[id].hidePanel(); windowObject.hidePanel();
} }
}, },
@ -838,7 +836,7 @@ const ContainerService = {
} }
// all the configuration must go away now. // all the configuration must go away now.
this._windowMap = {}; this._windowMap = new Map();
// Let's close all the container tabs (note: we don't care if containers // Let's close all the container tabs (note: we don't care if containers
// are supported but the current FF version). // are supported but the current FF version).