I was wondering whether it's possible to abstract the @Selectors and/or the @Action handlers from the @State class to a separate file? As the state grows bigger and as the selectors more complex, I'd like to move them to a separate file to keep the state class cleaner. Is there any way to do that in NGXS?
Edit: for future reference, I got an answer on the NGXS slack channel and it is indeed possible. We can create a separate selector class where to store all our selectors, passing them the state of interest as an argument.
export class EntityStateSelectors {
@Selector([EntityState])
thing(state: EntityStateModel) {
return state.thing;
}
}
As of now I still haven't figured out how to do the same for the action handlers, but extracting the selectors to a separate file already cleaned up the state class a lot !