mirror of
https://github.com/strapi/strapi.git
synced 2025-08-12 18:53:23 +00:00
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
![]() |
/**
|
||
|
* The global state selectors
|
||
|
*/
|
||
|
|
||
|
import { createSelector } from 'reselect';
|
||
|
|
||
|
const selectGlobal = () => (state) => state.get('global');
|
||
|
|
||
|
const selectCurrentUser = () => createSelector(
|
||
|
selectGlobal(),
|
||
|
(globalState) => globalState.get('currentUser')
|
||
|
);
|
||
|
|
||
|
const selectLoading = () => createSelector(
|
||
|
selectGlobal(),
|
||
|
(globalState) => globalState.get('loading')
|
||
|
);
|
||
|
|
||
|
const selectError = () => createSelector(
|
||
|
selectGlobal(),
|
||
|
(globalState) => globalState.get('error')
|
||
|
);
|
||
|
|
||
|
const selectRepos = () => createSelector(
|
||
|
selectGlobal(),
|
||
|
(globalState) => globalState.getIn(['userData', 'repositories'])
|
||
|
);
|
||
|
|
||
|
const selectLocationState = () => {
|
||
|
let prevRoutingState;
|
||
|
let prevRoutingStateJS;
|
||
|
|
||
|
return (state) => {
|
||
|
const routingState = state.get('route'); // or state.route
|
||
|
|
||
|
if (!routingState.equals(prevRoutingState)) {
|
||
|
prevRoutingState = routingState;
|
||
|
prevRoutingStateJS = routingState.toJS();
|
||
|
}
|
||
|
|
||
|
return prevRoutingStateJS;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export {
|
||
|
selectGlobal,
|
||
|
selectCurrentUser,
|
||
|
selectLoading,
|
||
|
selectError,
|
||
|
selectRepos,
|
||
|
selectLocationState,
|
||
|
};
|