mirror of
https://github.com/bendtherules/ts-transformer-visualizer.git
synced 2026-08-18 22:01:45 +00:00
redux - Add store, action, reducer for sourceFiles
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -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 }
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user