- initial;
This commit is contained in:
15
src/store/actions.js
Normal file
15
src/store/actions.js
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
|
||||
export const actionsAlpha = (set, get, api) => ({
|
||||
setAsyncRequest: () => {
|
||||
const num = get.isAsyncRequest();
|
||||
set.isAsyncRequest(num + 1);
|
||||
},
|
||||
unsetAsyncRequest: () => {
|
||||
const num = get.isAsyncRequest();
|
||||
set.isAsyncRequest(num - 1 < 0 ? 0 : num - 1);
|
||||
},
|
||||
})
|
||||
|
||||
export const actionsBeta = (set, get, api) => ({
|
||||
});
|
||||
20
src/store/index.js
Normal file
20
src/store/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { mapValuesKey } from 'zustand-x';
|
||||
|
||||
// stores
|
||||
import { mainStore } from './main';
|
||||
|
||||
// Global store - initial data
|
||||
const dashboardStore = {
|
||||
main: mainStore
|
||||
};
|
||||
|
||||
// Global hook selectors
|
||||
export const useStore = () => mapValuesKey('use', dashboardStore);
|
||||
// Global tracked hook selectors
|
||||
export const useTrackedStore = () => mapValuesKey('useTracked', dashboardStore);
|
||||
// Global getter selectors
|
||||
export const storeGet = mapValuesKey('get', dashboardStore);
|
||||
// Global actions
|
||||
export const storeSet = mapValuesKey('set', dashboardStore);
|
||||
|
||||
export default dashboardStore;
|
||||
6
src/store/initial.js
Normal file
6
src/store/initial.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const initialStore = {
|
||||
// ui related
|
||||
isAsyncRequest: 0, // number
|
||||
}
|
||||
|
||||
export default initialStore;
|
||||
11
src/store/main.js
Normal file
11
src/store/main.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createStore } from 'zustand-x';
|
||||
|
||||
import zustandXOpts from './zustand-x-opts';
|
||||
import initialStore from './initial';
|
||||
import selectors from './selectors';
|
||||
import { actionsAlpha, actionsBeta } from './actions';
|
||||
|
||||
export const mainStore = createStore('main')(initialStore, zustandXOpts)
|
||||
.extendSelectors(selectors)
|
||||
.extendActions(actionsAlpha)
|
||||
.extendActions(actionsBeta);
|
||||
10
src/store/selectors.js
Normal file
10
src/store/selectors.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { isEmpty } from 'ramda';
|
||||
|
||||
const selectors = (state, get, api) => ({
|
||||
getToken: () => {
|
||||
const userData = get.userData();
|
||||
return userData.access && !isEmpty(userData.access) ? userData.access : null;
|
||||
},
|
||||
})
|
||||
|
||||
export default selectors;
|
||||
16
src/store/zustand-x-opts.js
Normal file
16
src/store/zustand-x-opts.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const zustandXOpts = {
|
||||
devtools: {
|
||||
enabled: true
|
||||
},
|
||||
persist: {
|
||||
enabled: true,
|
||||
partialize: (state) => ({
|
||||
userData: state.userData,
|
||||
hubsList: state.hubsList,
|
||||
chosenHub: state.chosenHub,
|
||||
groups: state.groups,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
export default zustandXOpts;
|
||||
Reference in New Issue
Block a user