Last active
June 8, 2019 06:49
-
-
Save biancadanforth/c620aa583d817794ed1589ff95775c66 to your computer and use it in GitHub Desktop.
HostVsStoresRouter class Bug 1542035
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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