File size: 992 Bytes
84c1942
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export interface IFiles {
  [path: string]: {
    code: string | null;
    savedCode: string | null;
    isBinary: boolean;
    path: string;
  };
}

export interface ISetupParams {
  /**
   * Eg. https://codesandbox.io
   */
  host: string;
  files: IFiles;
  sandboxId: string;
}

/**
 * An executor is responsible for the communication with the service that executes
 * the code. Examples of these services are:
 *
 * - Sandbox Service: this is the browser bundler
 * - SSE Service: this is an external container that executes the code
 *
 * The executor will set these services up, and update them when files change. It also
 * serves as the interface to communicate with the service.
 */
export interface IExecutor {
  sandboxId?: string;

  initialize(params: ISetupParams): Promise<void>;

  setup(): Promise<void>;
  dispose(): Promise<void>;
  updateFiles(newFiles: IFiles): void;

  on(event: string, listener: (data: any) => void): void;
  emit(event: string, data?: any): void;
}