Skip to content

Commit

Permalink
flow runtime small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 2, 2024
1 parent cbe046e commit ccf27ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 104 deletions.
12 changes: 0 additions & 12 deletions packages/eez-studio-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ export type LogItemType =
| "info"
| "debug";

export interface IComponentFlowState {
getComponentExecutionState<T>(): T | undefined;
setComponentExecutionState<T>(executionState: T): void;
evalExpression(expression: string): any;
evalTemplateLiteral(expression: string): any;
assignValue(assignableExpression: string, value: any): any;
propagateValue(output: string, value: any): void;
throwError(err: string): void;
log(type: LogItemType, message: string): void;
dispose: (() => void) | undefined;
}

////////////////////////////////////////////////////////////////////////////////

// must be serializable
Expand Down
1 change: 0 additions & 1 deletion packages/project-editor/flow/flow-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export interface IFlow {}

export interface IComponentState {
inputsData: Map<string, any>;
unreadInputsData: Set<string>;
asyncState: boolean;
executionState: any;
}
Expand Down
97 changes: 6 additions & 91 deletions packages/project-editor/flow/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import {
import { Flow } from "project-editor/flow/flow";
import { FlowTabState } from "project-editor/flow/flow-tab-state";
import { ConnectionLine } from "project-editor/flow/connection-line";
import { CatchErrorActionComponent } from "project-editor/flow/components/actions";
import { Component, Widget } from "project-editor/flow/component";
import { IEezObject } from "project-editor/core/object";
import type {
IComponentState,
IDataContext,
IFlowContext
IFlowContext,
IFlowState,
IRuntime
} from "project-editor/flow/flow-interfaces";
import { Page } from "project-editor/features/page/page";
import {
Expand Down Expand Up @@ -88,7 +89,7 @@ export enum StateMachineAction {

export type SingleStepMode = "step-into" | "step-over" | "step-out";

export abstract class RuntimeBase {
export abstract class RuntimeBase implements IRuntime {
state: State = State.STARTING;
isDebuggerActive = false;

Expand Down Expand Up @@ -375,17 +376,6 @@ export abstract class RuntimeBase {
}
}

removeQueueTasksForFlowState(flowState: FlowState) {
runInAction(() => {
const queueTasksBefore = flowState.runtime.queue.length;
flowState.runtime.queue = flowState.runtime.queue.filter(
queueTask => queueTask.flowState != flowState
);
const queueTasksAfter = flowState.runtime.queue.length;
flowState.numActiveComponents -= queueTasksBefore - queueTasksAfter;
});
}

skipNextQueueTask(nextQueueTask: QueueTask) {
if (this.state != State.PAUSED) {
return false;
Expand Down Expand Up @@ -522,8 +512,6 @@ export abstract class RuntimeBase {
);
}

sendResultToWorker(messageId: number, result: any, finalResult?: boolean) {}

onBreakpointAdded(component: Component) {}

onBreakpointRemoved(component: Component) {}
Expand Down Expand Up @@ -844,7 +832,7 @@ export abstract class RuntimeBase {
onKeyDown(e: KeyboardEvent) {}
}

export class FlowState {
export class FlowState implements IFlowState {
id = guid();
componentStates = new Map<Component, ComponentState>();
flowStates: FlowState[] = [];
Expand All @@ -867,7 +855,6 @@ export class FlowState {
isFinished: observable,
setComponentExecutionState: action,
isRunning: computed,
hasAnyDiposableComponent: computed,
finish: action,
timelinePosition: observable,
setComponentAsyncState: action
Expand Down Expand Up @@ -983,50 +970,19 @@ export class FlowState {
);
}

get hasAnyDiposableComponent() {
for (let [_, componentState] of this.componentStates) {
if (componentState.dispose) {
return true;
}
}
return false;
}

finish() {
this.runtime.destroyObjectLocalVariables(this);
this.flowStates.forEach(flowState => flowState.finish());
this.componentStates.forEach(componentState => componentState.finish());
this.runtime.logs.addLogItem(new ActionEndLogItem(this));
this.isFinished = true;
}

findCatchErrorActionComponent(): ComponentState | undefined {
const catchErrorActionComponent = this.flow.components.find(
component => component instanceof CatchErrorActionComponent
);
if (catchErrorActionComponent) {
return this.getComponentState(catchErrorActionComponent);
}

if (this.parentFlowState) {
return this.parentFlowState.findCatchErrorActionComponent();
}

return undefined;
}

log(type: LogItemType, message: string, component: Component | undefined) {
this.runtime.logs.addLogItem(
new LogItem(type, message, this, component)
);
}

logScpi(message: string, component: Component) {
this.runtime.logs.addLogItem(
new LogItem("scpi", message, this, component)
);
}

get debugInfo(): any {
return {
id: this.id,
Expand Down Expand Up @@ -1085,22 +1041,17 @@ export class FlowState {

export class ComponentState implements IComponentState {
inputsData = new Map<string, any>();
unreadInputsData = new Set<string>();
isRunning: boolean = false;
asyncState: boolean = false;
executionState: any;
dispose: (() => void) | undefined = undefined;

constructor(public flowState: FlowState, public component: Component) {
makeObservable(this, {
inputsData: observable,
unreadInputsData: observable,
isRunning: observable,
asyncState: observable,
executionState: observable,
dispose: observable,
setInputData: action,
markInputsDataRead: action
setInputData: action
});
}

Expand All @@ -1110,42 +1061,6 @@ export class ComponentState implements IComponentState {

setInputData(input: string, inputData: any) {
this.inputsData.set(input, inputData);
this.unreadInputsData.add(input);
}

markInputsDataRead() {
this.unreadInputsData.clear();
}

get connectedSequenceInputsSet() {
const inputConnections = new Set<string>();
for (const connectionLine of this.flowState.flow.connectionLines) {
if (
connectionLine.targetComponent == this.component &&
this.sequenceInputs.find(
input => input.name == connectionLine.input
)
) {
inputConnections.add(connectionLine.input);
}
}
return inputConnections;
}

get sequenceInputs() {
return this.component.inputs.filter(input => input.isSequenceInput);
}

get mandatoryDataInputs() {
return this.component.inputs.filter(
input => !input.isSequenceInput && !input.isOptionalInput
);
}

finish() {
if (this.dispose) {
this.dispose();
}
}

get debugInfo() {
Expand Down

0 comments on commit ccf27ec

Please sign in to comment.