import {createStore, combineReducers, applyMiddleware}      from "redux";
import thunk                                                from "redux-thunk";
import promiseReducer       								from "./promiseReducer";
import authReducer 											from "./authReducer";
import {actionFindUser} 									from "../actions/actionFindUser";
import {actionSnippetFindByOwner} 							from "../actions/actionSnippetFindByOwner";

export const store = createStore(
	combineReducers({promise: promiseReducer,auth: authReducer}),
	applyMiddleware(thunk)
);

store.subscribe(() => console.log(store.getState()));

if (localStorage.authToken) {
	store.dispatch(actionFindUser());
	store.dispatch(actionSnippetFindByOwner(store.getState().auth.payload.sub.id));
}
