Skip to content

Commit

Permalink
Merge pull request #609 from shopgate/PWA-1664-remove-redundant-selec…
Browse files Browse the repository at this point in the history
…tor-getUserLogin

Removed duplicate getUserLogin selector
  • Loading branch information
fkloes committed Apr 8, 2019
2 parents 3496e9c + aa14bdc commit 4c3a89d
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions libraries/common/selectors/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,40 @@ import { getUrl } from './url';
export const getUserState = state => state.user;

/**
* @param {Object} state The current application state.
* @return {Object}
* Gets user.login from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const getUserData = createSelector(
export const getLoginData = createSelector(
getUserState,
(user) => {
if (!user.data) {
if (!user || !user.login) {
return null;
}

return user.data;
return user.login;
}
);

/**
* @param {Object} state The current application state.
* @return {Object|null}
* @deprecated
*/
export const getUserLogin = createSelector(
export const getUserLogin = getLoginData;

/**
* @param {Object} state The current application state.
* @return {Object}
*/
export const getUserData = createSelector(
getUserState,
(userState) => {
if (!userState) {
(user) => {
if (!user.data) {
return null;
}

return userState.login;
return user.data;
}
);

Expand All @@ -43,7 +51,7 @@ export const getUserLogin = createSelector(
* @return {boolean}
*/
export const isUserLoggedIn = createSelector(
getUserLogin,
getLoginData,
(login) => {
if (!login) {
return false;
Expand Down Expand Up @@ -98,19 +106,21 @@ export const getUserEmail = createSelector(
}
);

/**
* Gets user.login from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const getLoginData = state => state.user.login;

/**
* Selects the disabled state of the login action from the redux store.
* @param {Object} state The application state.
* @return {Object|null}
*/
export const isUserLoginDisabled = state => getLoginData(state).disabled;
export const isUserLoginDisabled = createSelector(
getLoginData,
(login) => {
if (!login) {
return false;
}

return login.disabled;
}
);

/**
* Gets the register url.
Expand Down

0 comments on commit 4c3a89d

Please sign in to comment.