在rxjs中映射只添加新项而不删除旧项

时间:2018-01-08 17:53:13

标签: javascript rxjs

我有一段代码,如果Api请求有一个needRefresh布尔值,它将调用服务器并将新数据映射到缓存集。因为它会将新项目从服务器映射到缓存集,但如果从服务器中删除项目,则不会从缓存集中删除它们。我该如何修复这个rxjs?

if (needsRefresh) {
            console.log('refreshed');
            let firstRun = true;
            return Observable.if(
                () => {
                    if (firstRun) {
                        firstRun = false;
                        return true;
                    }
                    else {
                        return false;
                    }
                },
                //this is the mapping code probably where the problem is
                this.requestSet(key, where).switchMap(() => this._cachedSets.get(key)),
                this._cachedSets.get(key)
            );
        }
        else {
            return this._cachedSets.get(key);
        }

0 个答案:

没有答案