|
@@ -1,6 +1,6 @@
|
|
|
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
|
import thunk from 'redux-thunk';
|
|
|
-import authReducer from './auth_reducer';
|
|
|
+import { authReducer } from './auth_reducer';
|
|
|
|
|
|
const LOGIN = 'LOGIN';
|
|
|
const LOGOUT = 'LOGOUT';
|
|
@@ -9,21 +9,7 @@ const PENDING = 'PENDING';
|
|
|
const RESOLVED = 'RESOLVED';
|
|
|
const REJECTED = 'REJECTED';
|
|
|
|
|
|
-const promiseReducer = (state, action) => {
|
|
|
-// if (action.type === LOGIN || action.type === LOGOUT) {
|
|
|
-// return {}
|
|
|
-// }
|
|
|
-// if (action.type === PROMISE) {
|
|
|
-// return{
|
|
|
-// ...state,
|
|
|
-// [action.name]: {
|
|
|
-// status: action.status,
|
|
|
-// payload: (action.status === PENDING && state[action.name] && state[action.name].payload) || action.payload, // зачем эта проверка?
|
|
|
-// error: action.error
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return state
|
|
|
+const promiseReducer = (state={}, action) => {
|
|
|
switch(action.type) {
|
|
|
case LOGIN:
|
|
|
return {};
|
|
@@ -43,7 +29,7 @@ const promiseReducer = (state, action) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const actionPromise = (name, promise) => {
|
|
|
+export const actionPromise = (name, promise) => {
|
|
|
const actionPending = () => ({ type: PROMISE, name, status: PENDING, payload: null, error: null })
|
|
|
const actionResolved = (payload) => ({ type: PROMISE, name, status: RESOLVED, payload, error: null })
|
|
|
const actionRejected = (error) => ({ type: PROMISE, name, status: REJECTED, payload: null, error })
|
|
@@ -64,4 +50,6 @@ const actionPromise = (name, promise) => {
|
|
|
export const store = createStore(combineReducers({
|
|
|
auth: authReducer,
|
|
|
promise: promiseReducer
|
|
|
-}), applyMiddleware(thunk));
|
|
|
+}), applyMiddleware(thunk));
|
|
|
+
|
|
|
+store.subscribe(() => console.log('+++', store.getState()))
|