in desktop/src/@batch-flask/core/data/list-view/list-view.ts [34:88]
constructor(config: ListViewConfig<TEntity, TParams>) {
super(config);
this._getter = config.getter;
this._options = new ListOptions(config.initialOptions || {});
this.items = combineLatest([
this._params.pipe(switchMap(params => this.getCache(params).items)),
this._itemKeys.pipe(distinctUntilChanged()),
this._prepend.pipe(distinctUntilChanged()),
this._params,
]).pipe(
map(([items, itemKeys, prependKeys, params]) => {
prependKeys = prependKeys.filter((x: string) => !itemKeys.has(x)) as any;
const allKeys = prependKeys.concat(itemKeys.toJS());
let keys = allKeys;
if (this._options.maxItems) {
keys = allKeys.slice(0, this._options.maxItems);
}
return List<TEntity>(keys.map((x: string) => {
const item = items.get(x);
if (!item && prependKeys.has(x)) {
return new this._getter.type({ ...params, [this.cache.uniqueField]: x });
}
return item;
}).filter((item) => {
if (!item) {
return false;
}
const matcher = new FilterMatcher<TEntity>();
if (this._options.filter && prependKeys.has(item[this.cache.uniqueField])) {
return matcher.test(this._options.filter, item);
}
return true;
}));
}),
distinctUntilChanged((a, b) => a.equals(b)),
takeUntil(this.isDisposed),
publishReplay(1),
refCount(),
);
this.hasMore = this._hasMore.asObservable();
this.deleted.subscribe((deletedKey) => {
this._setItemKeys(OrderedSet<string>(this._itemKeys.value.filter((key) => key !== deletedKey)));
});
this._cacheCleared.subscribe(() => {
this._setItemKeys(OrderedSet<string>([]));
this._handleChanges();
this._hasMore.next(true);
this.fetchNext();
});
}