implement .size for all observable maps

as SortedMapList uses it, putting undefined in its list
initially when missing, creating a crash in
the TemplateView that renders it
This commit is contained in:
Bruno Windels 2020-11-05 12:00:17 +01:00
parent dc05a163df
commit b27f6a067f
3 changed files with 26 additions and 3 deletions

View File

@ -78,4 +78,8 @@ export class ApplyMap extends BaseObservableMap {
[Symbol.iterator]() {
return this._source[Symbol.iterator]();
}
get size() {
return this._source.size;
}
}

View File

@ -41,4 +41,12 @@ export class BaseObservableMap extends BaseObservable {
h.onRemove(key, value);
}
}
[Symbol.iterator]() {
throw new Error("unimplemented");
}
get size() {
throw new Error("unimplemented");
}
}

View File

@ -71,10 +71,11 @@ export class FilteredMap extends BaseObservableMap {
}
onRemove(key, value) {
if (this._filter && !this._included.get(key)) {
return;
const wasIncluded = !this._filter || this._included.get(key);
this._included.delete(key);
if (wasIncluded) {
this.emitRemove(key, value);
}
this.emitRemove(key, value);
}
onUpdate(key, value, params) {
@ -117,6 +118,16 @@ export class FilteredMap extends BaseObservableMap {
[Symbol.iterator]() {
return new FilterIterator(this._source, this._included);
}
get size() {
let count = 0;
this._included.forEach(included => {
if (included) {
count += 1;
}
});
return count;
}
}
class FilterIterator {