Skip to content

Observing state changes in effects #4692

Answered by david-shortman
STOWouters asked this question in Q&A
Discussion options

You must be logged in to vote

Yes there is a way. What you want is to have a selector that only emits a new value when your parameters have actually changed:

@Injectable()
export class ItemsStore extends ComponentStore<ItemsState> {
  // ...

  // 👇 Declare selectors that can be memoized, and will only emit distinct values
  page$ = this.select((state) => state.page);
  filters$ = this.select((state) => state.filters);
  // 👇 Then create a composite selector that will only emit a new value when one of the input selectors emits a new, distinct value
  itemsRequestParams$ = this.select(
    this.page$,
    this.filters$,
    (page, filters) => ({
      page: state.page + 1,
      filters: state.filters,
    })
  );

  f…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by STOWouters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants