redux - Add store, action, reducer for sourceFiles

This commit is contained in:
2020-01-24 17:42:57 +05:30
parent f98fbed17b
commit 2737807289
4 changed files with 94 additions and 0 deletions
+22
View File
@@ -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<typeof rootReducer>;
export default function configureStore() {
const middlewares = [];
const middleWareEnhancer = applyMiddleware(...middlewares);
const store = createStore(
rootReducer,
composeWithDevTools(middleWareEnhancer)
);
return store;
}
+16
View File
@@ -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 }
};
}
+31
View File
@@ -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;
}
}
+25
View File
@@ -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;