Observing state changes in effects #4692
Unanswered
STOWouters
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello all,
I have a component store that keeps track of the current page as well as the active filters. There is also some form of pagination which will call the
fetchItems()
effect under some condition (e.g., when you scroll down far enough). The implementation looks something like this:The issue here is that the
patchState
call causes the selector in the first line to be triggered again, which in turn will fetch the next page, causing an infinite loop of fetching the next page (until it runs out). I am wondering if I am doing something fundamentally wrong with this implementation or is there a way to patch a state without triggering the selector?I have also tried to use
withLatestFrom(this.select(state => ...))
ortake(1)
instead, but while that does stop the infinite loop, it does not observe the changes on the filters, which is kind of required since fetching the items from the currently running request (if any) should be cancelled whenever the filters change.Is there a way to observe changes in the state and cancel the running effect or another NgRx way to achieve this?
Beta Was this translation helpful? Give feedback.
All reactions