Операторы RxJS - подписка не начинается с вложенных операторов

У меня есть следующий фрагмент кода, который не работает, как ожидалось. FooService имеет функцию с именем doFoo где он возвращает Observable, который никогда не подписывается правильно. В самом коде я оставил 2 строки, где они указывают, в какой момент код не достигает.

PS: функция, которую использует фильтр, проходит по огромному списку, возможно, миллионам элементов внутри.

fooService.doFoo(layerId)
    .subscribe((tuple) => {
        console.log('Subscribed');  // Never reaches here
    })


FooService {


doFoo(layerId: string) {
    return this.getShoppingItems(layerId)
        .pipe (
            switchMap(shoppingItems => this.getMatchedShoppingItemsFromLayer((layerId, shoppingItems)))
        );
}

getMatchedShoppingItemsFromLayer(layerId, shoppingItems: ShoppingItems): Observable<ShoppingItemLayerTuple> {
    // Here the shoppingItems are arrived with no problem
    return this.shopLayerService.getLayerList(layerId)
        .pipe(
            switchMap((shopPartitions: ShopPartition) => shopPartitions.getPartitionList()),
            filter(partition => this.layerMatches(partition.getId(), shoppingItems)),
            map((partition) => {
                console.log('foo') // Never reaches here,
                return {bla, bla} as ShoppingItemLayerTuple;
            })
        );
}

layerMatches(partitionId: string, shoppingItems: ShoppingItems): boolean {
    shoppingItems.getItemsList().forEach((shoppingItem) => {
        const shoppingItemLayerId = '${fooPrefix}' + shoppingItem.getBla().getIdList()[0];
        if(partitionId === shoppingItemLayerId) {
            console.log('foo'); // Reaches here 27 times as expected
            return true;
        }
    });

    return false;   }

getShoppingItems(layerId: string): Observable<ShoppingItems> {
    return this.shopService.getSoppingItems(layerId);
}

}

0 ответов

Другие вопросы по тегам