I have two properties in state model, and I need an event on each one of them separately, but when both change at the same time I receive two events and I need only one something like ngxsOnChanges
Asked
Active
Viewed 118 times
1

marc_s
- 732,580
- 175
- 1,330
- 1,459

Yacov Barham
- 11
- 2
-
You might find these helpful: https://stackoverflow.com/q/44004144/2436787 and https://stackoverflow.com/q/66421744/2436787 – Richard.Davenport Aug 09 '21 at 14:12
2 Answers
0
You can use a selector to combine both of them and then you will be able to subscribe to this selector and use a debounce
.

Mateus Carniatto
- 341
- 2
- 8
0
You can join multiple selectors using the @Selector
decorator, but take care of the injectContainerState
selector option, which is disabled by default in NGXS v4 (It's better to set it to false
if you're using NGXS v3.x)
Then, you can subscribe to the new selector in your component.
@Selector([ZooState, PreferencesState])
static firstLocalPanda(state: string[], preferencesState: PreferencesStateModel) {
return state.find(
s => s.indexOf('panda') > -1 && s.indexOf(preferencesState.location)
);
}
@Selector([ZooState.firstLocalPanda])
static happyLocalPanda(panda: string) {
return 'happy ' + panda;
}
To learn more about joining selectors: https://www.ngxs.io/concepts/select#joining-selectors

Amer
- 6,162
- 2
- 8
- 34