mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
intial commit
This commit is contained in:
parent
1d82241d2c
commit
44e10599d7
25 changed files with 17375 additions and 0 deletions
45
src/redux/store.ts
Normal file
45
src/redux/store.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { createStore, applyMiddleware, combineReducers, compose, Store } from 'redux';
|
||||
|
||||
import { persistStore, persistReducer } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import createSagaMiddleware from 'redux-saga';
|
||||
import { connectRouter } from 'connected-react-router'
|
||||
import userReducer from '$redux/user/reducer';
|
||||
import userSaga from '$redux/user/sagas';
|
||||
import { createBrowserHistory } from 'history';
|
||||
import { PersistConfig, Persistor } from "redux-persist/es/types";
|
||||
import { routerMiddleware } from 'connected-react-router'
|
||||
|
||||
const userPersistConfig: PersistConfig = {
|
||||
key: 'user',
|
||||
whitelist: ['user', 'logo', 'provider', 'speed'],
|
||||
storage,
|
||||
};
|
||||
|
||||
export const sagaMiddleware = createSagaMiddleware();
|
||||
export const history = createBrowserHistory();
|
||||
|
||||
const composeEnhancers =
|
||||
typeof window === 'object' &&
|
||||
(<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
||||
? (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
|
||||
: compose;
|
||||
|
||||
export const store = createStore(
|
||||
combineReducers({
|
||||
user: persistReducer(userPersistConfig, userReducer),
|
||||
router: connectRouter(history),
|
||||
}),
|
||||
composeEnhancers(applyMiddleware(
|
||||
routerMiddleware(history),
|
||||
sagaMiddleware
|
||||
))
|
||||
);
|
||||
|
||||
export function configureStore(): { store: Store<any>, persistor: Persistor } {
|
||||
sagaMiddleware.run(userSaga);
|
||||
|
||||
const persistor = persistStore(store);
|
||||
|
||||
return { store, persistor };
|
||||
}
|
3
src/redux/user/actions.ts
Normal file
3
src/redux/user/actions.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { USER_ACTIONS } from "$redux/user/constants";
|
||||
|
||||
export const someAction = () => ({ type: USER_ACTIONS.SOME_ACTION });
|
3
src/redux/user/constants.ts
Normal file
3
src/redux/user/constants.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const USER_ACTIONS = {
|
||||
SOME_ACTION: 'SOME_ACTION',
|
||||
};
|
28
src/redux/user/reducer.ts
Normal file
28
src/redux/user/reducer.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { createReducer } from 'reduxsauce';
|
||||
import * as ACTIONS from "$redux/user/actions";
|
||||
import { USER_ACTIONS } from "$redux/user/constants";
|
||||
|
||||
export type IRootState = Readonly<{
|
||||
// key: string
|
||||
}>;
|
||||
|
||||
type UnsafeReturnType<T> = T extends (...args: any[]) => infer R ? R : any;
|
||||
interface ActionHandler<T> {
|
||||
(state: IRootState, payload: UnsafeReturnType<T>): IRootState;
|
||||
}
|
||||
|
||||
const someActionHandler: ActionHandler<typeof ACTIONS.someAction> = (state) => {
|
||||
return { ...state };
|
||||
};
|
||||
|
||||
const HANDLERS = {
|
||||
[USER_ACTIONS.SOME_ACTION]: someActionHandler,
|
||||
};
|
||||
|
||||
const INITIAL_STATE: IRootState = {
|
||||
// key: val,
|
||||
// key: val,
|
||||
// key: val
|
||||
};
|
||||
|
||||
export default createReducer(INITIAL_STATE, HANDLERS);
|
25
src/redux/user/sagas.ts
Normal file
25
src/redux/user/sagas.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects';
|
||||
import { delay } from 'redux-saga';
|
||||
import { USER_ACTIONS } from "$redux/user/constants";
|
||||
|
||||
// Worker Saga for SET_EDITOR_LOCATION_INPUT reducer
|
||||
/*
|
||||
function* fetchSuggestions({ payload }) {
|
||||
const { value } = payload;
|
||||
|
||||
yield delay(300);
|
||||
try {
|
||||
const results = yield call(someFunction, arguments);
|
||||
yield put({ type: TYPES.ANOTHER_ACTION, payload: { results } });
|
||||
} catch (e) {
|
||||
yield put({ type: TYPES.ANOTHER_ACTION, payload: { results } });
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
function* mySaga() {
|
||||
// fetch autocompletion on location input
|
||||
//yield takeLatest(TYPES.ACTION, function);
|
||||
}
|
||||
|
||||
export default mySaga;
|
Loading…
Add table
Add a link
Reference in a new issue