简体   繁体   中英

Refactor Nested FlatMap in RxJS

I have a itemsObservable , filtersObservable , and a queryObservable and feed their values to a function that takes a list of items, filter conditions, and a search query, and returns a filtered list.

Right now my code looks something like:

itemsObservable
    .flatMap(items => {
        filtersObservable
            .flatMap(filters => {
                queryObservable
                    .map(query => filterItems(items, filters, query))
             })
     });

Is there a better code pattern for this that eschews the deep nesting?

queryObservable.withLatestFrom(
    filtersObservable,
    itemsObservable,
    (query, filters, items) => filterItems(items, filters, query)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM