What is the difference between store.combine and combineLatest? #326
-
I would like to understand store.combine, but I can only find one example in the docs. I found this in a discussion: store.combine({
movies: store.pipe(selectAll()),
genres: store.pipe(selectEntities({ ref: GenresEntitiesRef })),
actors: store.pipe(selectEntities({ ref: ActorsEntitiesRef })),
})
.pipe(map(data => {
return data.movies.map(movie => {
return {
...movie,
genres: movie.genres.map(id => data.genres[id]),
actors: movie.actors.map(id => data.actors[id])
}
})
})); Is that equivalent to: combineLatest([
store.pipe(selectAll()),
store.pipe(selectEntities({ ref: GenresEntitiesRef })),
store.pipe(selectEntities({ ref: ActorsEntitiesRef })),
])
.pipe(map(([movies, genres, actors]) => {
return movies.map(movie => {
return {
...movie,
genres: movie.genres.map(id => genres[id]),
actors: movie.actors.map(id => actors[id])
}
})
})); I'm also interested if there is any difference when the entities come from different stores. Specifically, does combine wait for all observables to emit like combineLatest does, and is there any difference when all observables emit within the same tick? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The first example emits once even on multiple updates in the same tick. It works only when using selectors from the same store. If you want to use different stores, you can use |
Beta Was this translation helpful? Give feedback.
The first example emits once even on multiple updates in the same tick.
It works only when using selectors from the same store. If you want to use different stores, you can use
combineLatest
withauditTime(0)