diff --git a/src/expression/components/BitwiseResultView.tsx b/src/expression/components/BitwiseResultView.tsx index c24d99c..1d1bcc7 100644 --- a/src/expression/components/BitwiseResultView.tsx +++ b/src/expression/components/BitwiseResultView.tsx @@ -5,26 +5,23 @@ import BitwiseResultViewModel from './BitwiseResultViewModel'; import { Expression, ExpressionToken } from '../expression-interfaces'; import { OperatorToken, ScalarToken } from '../expression'; -type BitwiseOperationExpressionViewProps = { +type BitwiseResultViewProps = { expression: Expression; emphasizeBytes: boolean; } -type BitwiseOperationExpressionViewState = { +type BitwiseResultViewState = { } -export default class BitwiseResultView extends React.Component { - constructor(props: BitwiseOperationExpressionViewProps) { +export default class BitwiseResultView extends React.Component { + constructor(props: BitwiseResultViewProps) { super(props); this.state = {}; } render() { var rows = this.getRows(); - if(!rows) { - return null; - } - + return {rows} @@ -32,7 +29,7 @@ export default class BitwiseResultView extends React.Component } - getRows() : JSX.Element[] | null { + getRows() : JSX.Element[] { var model = BitwiseResultViewModel.createModel(this.props.expression, this.props.emphasizeBytes); return model.items.map((itm, i) => diff --git a/src/expression/module.tsx b/src/expression/module.tsx index e6b293a..e187ce4 100644 --- a/src/expression/module.tsx +++ b/src/expression/module.tsx @@ -12,7 +12,7 @@ const expressionAppModule = { canHandle: (input:string) => parser.canParse(input), handle: function(c: CommandInput) { var expr = parser.parse(c.input); - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); } }); } diff --git a/src/index.tsx b/src/index.tsx index ae9a122..6e63049 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -36,7 +36,7 @@ function initializeModules() { // Last command handler reports that input is unknown cmd.command({ canHandle: () => true, - handle: (c: CommandInput) => appData.appState.addCommandResult(c.input, ) + handle: (c: CommandInput) => appData.appState.addCommandResult(c.input, () => ) }); } diff --git a/src/networking/module.tsx b/src/networking/module.tsx index 8db74b0..51b0a82 100644 --- a/src/networking/module.tsx +++ b/src/networking/module.tsx @@ -25,18 +25,18 @@ const networkingAppModule = { return; if(result instanceof ParsingError) { - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); return; } if(result instanceof SubnetCommand) { - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); trackCommand('SubnetCommand', c.options); return; } if(result instanceof VpcCommand) { - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); trackCommand('VpcCommand', c.options); return; } @@ -56,7 +56,7 @@ const networkingAppModule = { trackCommand("IpAddressesInput", c.options); - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); } }); diff --git a/src/shell/AppState.ts b/src/shell/AppState.ts index 392fc51..2cc0f88 100644 --- a/src/shell/AppState.ts +++ b/src/shell/AppState.ts @@ -14,11 +14,13 @@ export type PersistedAppData = { export type CommandResultView = { key: number, input: string, - view: JSX.Element + view: ViewFactory }; export type AppStateChangeHandler = (state: AppState) => void; +type ViewFactory = () => JSX.Element; + export default class AppState { version: number = APP_VERSION; @@ -47,7 +49,7 @@ export default class AppState { this.donationClicked = persistData.donationClicked; } - addCommandResult(input : string, view : JSX.Element) { + addCommandResult(input : string, view : ViewFactory) { const key = generateKey(); this.commandResults.unshift({key, input, view}); log.debug(`command result added: ${input}`); diff --git a/src/shell/components/AppRoot.tsx b/src/shell/components/AppRoot.tsx index 0857fbd..78211f1 100644 --- a/src/shell/components/AppRoot.tsx +++ b/src/shell/components/AppRoot.tsx @@ -28,6 +28,7 @@ export default class AppRoot extends React.Component } refresh() { + console.log('refresh'); this.setState(this.props.appState); } @@ -39,7 +40,7 @@ export default class AppRoot extends React.Component var results = this.state.commandResults.map((r, i) => - {r.view} + {r.view()} ); return results; } diff --git a/src/shell/module.tsx b/src/shell/module.tsx index 6148c47..30ef963 100644 --- a/src/shell/module.tsx +++ b/src/shell/module.tsx @@ -17,19 +17,19 @@ const shellModule = { cmd.debugMode = appState.debugMode; appState.onChange(() => cmd.debugMode = appState.debugMode); - cmd.command("help", (c: CommandInput) => appState.addCommandResult(c.input, )); + cmd.command("help", (c: CommandInput) => appState.addCommandResult(c.input, () => )); cmd.command("clear", () => appState.clearCommandResults()); cmd.command("em", () => appState.toggleEmphasizeBytes()); cmd.command("dark", () => appState.setUiTheme('dark')); cmd.command("light", () => appState.setUiTheme('light')); cmd.command("midnight", () => appState.setUiTheme('midnight')); - cmd.command("about", (c: CommandInput) => appState.addCommandResult(c.input, )); - cmd.command("whatsnew", (c: CommandInput) => appState.addCommandResult(c.input, )); - cmd.command("guid", (c: CommandInput) => appState.addCommandResult(c.input, )); + cmd.command("about", (c: CommandInput) => appState.addCommandResult(c.input, () => )); + cmd.command("whatsnew", (c: CommandInput) => appState.addCommandResult(c.input, () => )); + cmd.command("guid", (c: CommandInput) => appState.addCommandResult(c.input, () => )); cmd.command("-notrack", () => {}); cmd.command("-debug", (c: CommandInput) => { appState.toggleDebugMode(); - appState.addCommandResult(c.input, ); + appState.addCommandResult(c.input, () => ); }); cmd.command("donate", (c:CommandInput) => { @@ -73,12 +73,12 @@ const shellModule = { const command = s.input.substring(7).trim(); const result = executeCommand(command); - appState.addCommandResult(s.input, ); + appState.addCommandResult(s.input, () => ); } }); }; - cmd.onError((input: string, err: Error) => appState.addCommandResult(input, )); + cmd.onError((input: string, err: Error) => appState.addCommandResult(input, () => )); } }