Debouncing Actions
There are situations when there is a need to debounce dispatched actions and reduce requests send to our API. Let's consider a simple application that renders a list of news and provides the ability to search among all of them:
In the above example we've got the app-news-portal
component that listens to the search
event, dispatched by the app-news-search
component. The search
method, invoked on the search
event, dispatches the SearchNews
action. Notice that the SearchNews
action is defined in the component file because it's never used by any other part of the application. We don't want to overload our server with requests thus we listen to the Actions
stream that pipes the SearchNews
action with debounceTime
operator. Let's look at the below code of how we would implement our NewsState
:
The above state is pretty simple. As you can see we don't create an action handler for the SearchNews
but it still will be passed via Actions
stream and debounced. It all depends on the task in practice but you're already informed about debouncing actions.
Last updated