forked from mystiq/hydrogen-web
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:
parent
dc05a163df
commit
b27f6a067f
3 changed files with 26 additions and 3 deletions
|
@ -78,4 +78,8 @@ export class ApplyMap extends BaseObservableMap {
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
return this._source[Symbol.iterator]();
|
return this._source[Symbol.iterator]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get size() {
|
||||||
|
return this._source.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,12 @@ export class BaseObservableMap extends BaseObservable {
|
||||||
h.onRemove(key, value);
|
h.onRemove(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Symbol.iterator]() {
|
||||||
|
throw new Error("unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
get size() {
|
||||||
|
throw new Error("unimplemented");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,10 +71,11 @@ export class FilteredMap extends BaseObservableMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemove(key, value) {
|
onRemove(key, value) {
|
||||||
if (this._filter && !this._included.get(key)) {
|
const wasIncluded = !this._filter || this._included.get(key);
|
||||||
return;
|
this._included.delete(key);
|
||||||
|
if (wasIncluded) {
|
||||||
|
this.emitRemove(key, value);
|
||||||
}
|
}
|
||||||
this.emitRemove(key, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdate(key, value, params) {
|
onUpdate(key, value, params) {
|
||||||
|
@ -117,6 +118,16 @@ export class FilteredMap extends BaseObservableMap {
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
return new FilterIterator(this._source, this._included);
|
return new FilterIterator(this._source, this._included);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get size() {
|
||||||
|
let count = 0;
|
||||||
|
this._included.forEach(included => {
|
||||||
|
if (included) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FilterIterator {
|
class FilterIterator {
|
||||||
|
|
Loading…
Add table
Reference in a new issue