diff --git a/src/store/index.tsx b/src/store/index.tsx new file mode 100644 index 0000000..3515acb --- /dev/null +++ b/src/store/index.tsx @@ -0,0 +1,22 @@ +import { createStore, combineReducers, applyMiddleware } from "redux"; +import { composeWithDevTools } from "redux-devtools-extension"; + +import { sourceFilesReducer } from "./sourceFiles/reducer"; + +const rootReducer = combineReducers({ + sourceFiles: sourceFilesReducer +}); + +export type AppState = ReturnType; + +export default function configureStore() { + const middlewares = []; + const middleWareEnhancer = applyMiddleware(...middlewares); + + const store = createStore( + rootReducer, + composeWithDevTools(middleWareEnhancer) + ); + + return store; +} diff --git a/src/store/sourceFiles/actions.ts b/src/store/sourceFiles/actions.ts new file mode 100644 index 0000000..6f1d41e --- /dev/null +++ b/src/store/sourceFiles/actions.ts @@ -0,0 +1,16 @@ +import * as ts from "typescript"; +import { INIT_SOURCEFILE, UPDATE_SOURCEFILE } from "./types"; + +export function initSourceFile(sourceFile: ts.SourceFile) { + return { + type: INIT_SOURCEFILE, + payload: { sourceFile } + }; +} + +export function updateSourceFile(sourceFile: ts.SourceFile) { + return { + type: UPDATE_SOURCEFILE, + payload: { sourceFile } + }; +} diff --git a/src/store/sourceFiles/reducer.ts b/src/store/sourceFiles/reducer.ts new file mode 100644 index 0000000..c7a0589 --- /dev/null +++ b/src/store/sourceFiles/reducer.ts @@ -0,0 +1,31 @@ +import { + SourceFilesState, + INIT_SOURCEFILE, + UPDATE_SOURCEFILE, + SourceFilesActionTypes +} from "./types"; + +const initialState: SourceFilesState = { + inititalSourceFile: undefined, + currentSourceFile: undefined +}; + +export function sourceFilesReducer( + state = initialState, + action: SourceFilesActionTypes +): SourceFilesState { + switch (action.type) { + case INIT_SOURCEFILE: + return { + ...state, + inititalSourceFile: action.payload.sourceFile + }; + case UPDATE_SOURCEFILE: + return { + ...state, + currentSourceFile: action.payload.sourceFile + }; + default: + return state; + } +} diff --git a/src/store/sourceFiles/types.ts b/src/store/sourceFiles/types.ts new file mode 100644 index 0000000..899528e --- /dev/null +++ b/src/store/sourceFiles/types.ts @@ -0,0 +1,25 @@ +import * as ts from "typescript"; + +// Describing the shape of the sourceFile's slice of state +export interface SourceFilesState { + inititalSourceFile?: ts.SourceFile; + currentSourceFile?: ts.SourceFile; +} + +// Describing the different ACTION NAMES available +export const INIT_SOURCEFILE = "INIT_SOURCEFILE"; +export const UPDATE_SOURCEFILE = "UPDATE_SOURCEFILE"; + +interface InitSourceFileAction { + type: typeof INIT_SOURCEFILE; + payload: { sourceFile: ts.SourceFile }; +} + +interface UpdateSourceFileAction { + type: typeof UPDATE_SOURCEFILE; + payload: { sourceFile: ts.SourceFile }; +} + +export type SourceFilesActionTypes = + | InitSourceFileAction + | UpdateSourceFileAction;