FIX;Auth selector native types
This commit is contained in:
parent
c46ec61fd5
commit
46cc148341
14 changed files with 31517 additions and 78283 deletions
|
@ -14,7 +14,8 @@
|
|||
"@treejs/types": "0.12.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@reduxjs/toolkit": "1.8.0",
|
||||
"@reduxjs/toolkit": "^1.8.0",
|
||||
"proxy-memoize": "0.3.8",
|
||||
"redux": "4.0.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { type Selector, createSelector } from '@reduxjs/toolkit';
|
||||
import memoize from 'proxy-memoize';
|
||||
import { DefaultRootState } from 'react-redux';
|
||||
|
||||
import { ROOT_REDUCER_NAME } from '@treejs/constants/redux';
|
||||
|
||||
|
@ -7,12 +8,12 @@ import { IAuthOption } from './types';
|
|||
|
||||
const reducer = <P>(state: any): IAuthOption<P> => state[ROOT_REDUCER_NAME][AUTH_REDUCER_NAME];
|
||||
|
||||
export const isAuthenticated = createSelector<[Selector<any, IAuthOption<any>>], boolean>(
|
||||
[reducer],
|
||||
(state) => state.authenticated
|
||||
);
|
||||
export const isAuthenticated = memoize<DefaultRootState, boolean>((state) => {
|
||||
return reducer<Record<string, unknown>>(state).authenticated;
|
||||
});
|
||||
|
||||
export const getAuthenticateAttribute = createSelector<
|
||||
[Selector<any, IAuthOption<any>>, Selector<{ name: keyof IAuthOption<any> }, string>],
|
||||
keyof IAuthOption<any>
|
||||
>([reducer, (_, { name }) => name], (state, name) => state[name]);
|
||||
export const getAuthenticateAttribute = memoize<[DefaultRootState, { attrName: string }], unknown>(
|
||||
([state, { attrName }]) => {
|
||||
return reducer<Record<string, unknown>>(state)[attrName];
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue