lib - Add node highlighting and consume in log-identifier

This commit is contained in:
2020-01-29 13:42:38 +05:30
parent 3feecc6750
commit a32cd478ac
10 changed files with 153 additions and 60 deletions
+33 -5
View File
@@ -1,22 +1,50 @@
import * as ts from "typescript";
import { INIT_SOURCEFILE, UPDATE_SOURCEFILE, CLEAR_SOURCEFILE } from "./types";
import {
INIT_SOURCEFILE,
UPDATE_SOURCEFILE,
CLEAR_SOURCEFILE,
HIGHLIGHT_NODE,
CLEAR_HIGHLIGHTED_NODES,
InitSourceFileAction,
UpdateSourceFileAction,
ClearSourceFileAction,
HighlightNodeAction,
ClearHighlightedNodesAction
} from "./types";
export function initSourceFile(sourceFile: ts.SourceFile) {
export function initSourceFile(
sourceFile: ts.SourceFile
): InitSourceFileAction {
return {
type: INIT_SOURCEFILE,
payload: { sourceFile }
};
}
export function updateSourceFile(sourceFile: ts.SourceFile) {
export function updateSourceFile(
sourceFile: ts.SourceFile
): UpdateSourceFileAction {
return {
type: UPDATE_SOURCEFILE,
payload: { sourceFile }
};
}
export function clearSourceFile() {
export function clearSourceFile(): ClearSourceFileAction {
return {
type: CLEAR_SOURCEFILE,
type: CLEAR_SOURCEFILE
};
}
export function highlightNode(node: ts.Node): HighlightNodeAction {
return {
type: HIGHLIGHT_NODE,
payload: { node }
};
}
export function clearHighlightedNodes(): ClearHighlightedNodesAction {
return {
type: CLEAR_HIGHLIGHTED_NODES
};
}
+28 -4
View File
@@ -2,17 +2,24 @@ import {
INIT_SOURCEFILE,
UPDATE_SOURCEFILE,
CLEAR_SOURCEFILE,
HIGHLIGHT_NODE,
CLEAR_HIGHLIGHTED_NODES,
SourceFilesState,
SourceFilesActionTypes
HighlightedNodesState,
SourceFilesActionTypes,
HighlightNodeActionTypes
} from "./types";
const initialState: SourceFilesState = {
const initialSourceFileState: SourceFilesState = {
inititalSourceFile: undefined,
currentSourceFile: undefined
};
const initialHighlightedNodesState: HighlightedNodesState = {
nodes: []
};
export function sourceFilesReducer(
state = initialState,
state = initialSourceFileState,
action: SourceFilesActionTypes
): SourceFilesState {
switch (action.type) {
@@ -28,7 +35,24 @@ export function sourceFilesReducer(
currentSourceFile: action.payload.sourceFile
};
case CLEAR_SOURCEFILE:
return initialState;
return initialSourceFileState;
default:
return state;
}
}
export function highlightedNodesReducer(
state = initialHighlightedNodesState,
action: HighlightNodeActionTypes
): HighlightedNodesState {
switch (action.type) {
case HIGHLIGHT_NODE:
return {
...state,
nodes: [...state.nodes, action.payload.node]
};
case CLEAR_HIGHLIGHTED_NODES:
return initialHighlightedNodesState;
default:
return state;
}
+23 -3
View File
@@ -6,26 +6,46 @@ export interface SourceFilesState {
currentSourceFile?: ts.SourceFile;
}
// slice for highlighted nodes
export interface HighlightedNodesState {
nodes: ts.Node[];
}
// Describing the different ACTION NAMES available
export const INIT_SOURCEFILE = "INIT_SOURCEFILE";
export const UPDATE_SOURCEFILE = "UPDATE_SOURCEFILE";
export const CLEAR_SOURCEFILE = "CLEAR_SOURCEFILE";
export const HIGHLIGHT_NODE = "HIGHLIGHT_NODE";
export const CLEAR_HIGHLIGHTED_NODES = "CLEAR_HIGHLIGHTED_NODES";
interface InitSourceFileAction {
export interface InitSourceFileAction {
type: typeof INIT_SOURCEFILE;
payload: { sourceFile: ts.SourceFile };
}
interface UpdateSourceFileAction {
export interface UpdateSourceFileAction {
type: typeof UPDATE_SOURCEFILE;
payload: { sourceFile: ts.SourceFile };
}
interface ClearSourceFileAction {
export interface ClearSourceFileAction {
type: typeof CLEAR_SOURCEFILE;
}
export interface HighlightNodeAction {
type: typeof HIGHLIGHT_NODE;
payload: { node: ts.Node };
}
export interface ClearHighlightedNodesAction {
type: typeof CLEAR_HIGHLIGHTED_NODES;
}
export type SourceFilesActionTypes =
| InitSourceFileAction
| UpdateSourceFileAction
| ClearSourceFileAction;
export type HighlightNodeActionTypes =
| HighlightNodeAction
| ClearHighlightedNodesAction;