Combine several recent versions of observables, ngrx

I have product, which are tied comments, attachments, images. All of these items are taken from the repository ngrx, which means that all of these items are observable. My question is: how do I combine these elements?

I usually use:

combineLatest(selectProducts, selectProductComments, (products, comments) => {
  // attach comments to products here
})

However, it combineLatestworks with 2 sets of observables and I have 4 of them. So what is the easiest way to do this?


Here is the context:

So, we show the list productswhen each product is clicked, product information is downloaded and displayed in a pop-up window. This information contains comments, attachmentsand images. This step can be called the phase DEEP_LOADINGwhere, when the user clicks on products, comments, attachments and images are downloaded via http.

The user can also add new images, comments or attachments. When he does, he is added to the list of comments commentwith the status pendingset to true. When the HTTP request resolves, this commentwait property is set to false.

, comments, attachments images. , , comments - , ( ), , .

: ( , , , ..)

export function commentReducer(state, action) {
    switch (action.type) {
        case 'SET_COMMENT':
            // when we set we have to keep the pending comments,
            // so when we open another product, then switch back to the original one
            // if the pending comment is still pending it should display as pending
            const newState = state.filter((c: AppComment) => c.pending);
            newState.push(action.payload);
            return newState;
        case 'CLEAR':
            return initialState;
    }
}
+4
1

combineLatest X. , .

:

combineLatest(v1$, v2$, v3$, v4$, (v1, v2, v3, v4) => {
  console.log(v1, v2, v3, v4);
})
+2

Source: https://habr.com/ru/post/1690679/


All Articles