progress and some refactoring
This commit is contained in:
parent
d236eca5e5
commit
d8ca2f3999
25 changed files with 376 additions and 163 deletions
18
util/defaultmap.js
Normal file
18
util/defaultmap.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
export class DefaultMap {
|
||||
constructor(defaultValue, ...rest) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.m = new Map(rest);
|
||||
}
|
||||
getdefault(key, addToMapping = false) {
|
||||
return this.m.get(key) || (() => {
|
||||
const val = this.defaultValue(key);
|
||||
if (addToMapping)
|
||||
this.m.set(key, val);
|
||||
return val;
|
||||
})();
|
||||
}
|
||||
entries() {
|
||||
return this.m.entries();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue