Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Last active November 21, 2019 08:40
Show Gist options
  • Save zzdjk6/7df1ace324e977148cf95b3cb9c4a0ff to your computer and use it in GitHub Desktop.
Save zzdjk6/7df1ace324e977148cf95b3cb9c4a0ff to your computer and use it in GitHub Desktop.
// Selectors
// Select the whole loading state object
export const selectLoadingState = (state: RootState) => state.ui.loading;
// Select whether a given routine is loading
export const selectLoading = (routineType: string) => {
return createSelector([selectLoadingState], (state: LoadingState) => {
return !!state[routineType];
});
};
// Select whether any routine is loading
export const selectAnyLoading = createSelector([selectLoadingState], (state: LoadingState) => {
return Object.values(state).some(val => val);
});
// Select whether a given set of routines are loading
export const selectSomeLoading = (routineTypes: Array<string>) => {
return createSelector([selectLoadingState], (state: LoadingState) => {
return routineTypes.some(routineType => state[routineType]);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment