update BlockService to use the new type union feature of tsgen. strongly type the arguments to BlockService.SendCommand

This commit is contained in:
sawka
2024-06-12 13:47:13 -07:00
parent 605b9ea048
commit 083e00227e
13 changed files with 195 additions and 101 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ const Block = ({ blockId, onClose }: BlockProps) => {
} else if (blockData.view === "plot") {
blockElem = <PlotView />;
} else if (blockData.view === "codeedit") {
blockElem = <CodeEditView />;
blockElem = <CodeEditView text={null} />;
}
return (
<div className="block" ref={blockRef}>
+1 -1
View File
@@ -8,7 +8,7 @@ import * as WOS from "./wos";
// blockservice.BlockService (block)
class BlockServiceType {
// send command to block
SendCommand(blockid: string, command: MetaType): Promise<void> {
SendCommand(blockid: string, cmd: BlockCommand): Promise<void> {
return WOS.callBackendService("block", "SendCommand", Array.from(arguments))
}
}
+5 -6
View File
@@ -49,7 +49,10 @@ function handleResize(fitAddon: FitAddon, blockId: string, term: Terminal) {
const oldCols = term.cols;
fitAddon.fit();
if (oldRows !== term.rows || oldCols !== term.cols) {
const resizeCommand = { command: "controller:input", termsize: { rows: term.rows, cols: term.cols } };
const resizeCommand: BlockInputCommand = {
command: "controller:input",
termsize: { rows: term.rows, cols: term.cols },
};
services.BlockService.SendCommand(blockId, resizeCommand);
}
}
@@ -78,17 +81,13 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
newTerm.loadAddon(newFitAddon);
newTerm.open(connectElemRef.current);
newFitAddon.fit();
// BlockService.SendCommand(blockId, {
// command: "controller:input",
// termsize: { rows: newTerm.rows, cols: newTerm.cols },
// });
services.BlockService.SendCommand(blockId, {
command: "controller:input",
termsize: { rows: newTerm.rows, cols: newTerm.cols },
});
newTerm.onData((data) => {
const b64data = btoa(data);
const inputCmd = { command: "controller:input", blockid: blockId, inputdata64: b64data };
const inputCmd: BlockInputCommand = { command: "controller:input", inputdata64: b64data };
services.BlockService.SendCommand(blockId, inputCmd);
});
+31 -1
View File
@@ -14,6 +14,10 @@ declare global {
meta: MetaType;
};
type BlockCommand = {
command: string;
} & ( BlockMessageCommand | BlockInputCommand | BlockSetViewCommand | BlockSetMetaCommand );
// wstore.BlockDef
type BlockDef = {
controller?: string;
@@ -22,6 +26,32 @@ declare global {
meta?: MetaType;
};
// blockcontroller.BlockInputCommand
type BlockInputCommand = {
command: "controller:input";
inputdata64?: string;
signame?: string;
termsize?: TermSize;
};
// blockcontroller.BlockMessageCommand
type BlockMessageCommand = {
command: "message";
message: string;
};
// blockcontroller.BlockSetMetaCommand
type BlockSetMetaCommand = {
command: "setmeta";
meta: MetaType;
};
// blockcontroller.BlockSetViewCommand
type BlockSetViewCommand = {
command: "setview";
view: string;
};
// wstore.Client
type Client = WaveObj & {
mainwindowid: string;
@@ -62,7 +92,7 @@ declare global {
type MetaType = {[key: string]: any}
// servicemeta.MethodMeta
// tsgenmeta.MethodMeta
type MethodMeta = {
Desc: string;
ArgNames: string[];