I am new to NgRx and not an expert at RxJs hence the question. We have to use it in an angular app. I have a component where user selects an orderId from a drop down in one of its fields. An other component has a search button to trigger a search based on the order id. Searching returns a list of items related the orderId and shows it in a table component. I am saving the order id in the store in the view state as soon as the user selects it. Now when the user clicks on search I have to get this order Id from the store. I tried to do it like so :
onClickSearch() {
this.store.pipe(select(fromOrderIdSelectors.selectOrderId))
.subscribe((orderId: string) => {
this.store.dispatch(fromOrderActions.getOrderItems({orderId : orderId});
}));
}
This works fine for the search but since I am subscribing to the store now, the search request is dispatched as soon as the order id is set in the store even from any other place in the app. Should I get and unsubscribe every time to the observable manually? Or is there some RxJs magic I can use to implement this.