Skip to content

Instantly share code, notes, and snippets.

@biancadanforth
Last active June 8, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biancadanforth/c620aa583d817794ed1589ff95775c66 to your computer and use it in GitHub Desktop.
Save biancadanforth/c620aa583d817794ed1589ff95775c66 to your computer and use it in GitHub Desktop.
HostVsStoresRouter class Bug 1542035
// in storage actor's `populateStoresForHost` method...
this.hostVsStores = new HostVsStoresRouter(host);
// Add an intermediary "area" layer between host and storeMap in this.hostVsStores
class HostVsStoresRouter {
constructor(host) {
this.DEFAULT_AREA = "local";
// a triple nested map: host => areaMap, where areaMap is area => storeMap and storeMap is key => value
this.router = (new Map()),set(host, new Map());
},
get(host, area = this.DEFAULT_AREA) {
return this.router.get(host).get(area);
},
set(host, storeMap, area = this.DEFAULT_AREA) {
this.router.get(host).set(area, storeMap);
},
// Needed for getValuesForHost, which should return an array of `item` objects of the form {name, value, area}
getAllItems(host) {
const items = [];
for (const areaMap of this.router.get(host)) {
for (const [area, storeMap] of Object.entries(areaMap)) {
for (const [name, value] of Object.entries(storeMap)) {
const item = {name, value, area};
items.push(item);
}
}
}
return items;
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment