Skip to content

Commit

Permalink
chore: define type for fn used as param
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungeunni committed Feb 9, 2023
1 parent 7816b8a commit 58b2ee5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
12 changes: 4 additions & 8 deletions common/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,17 @@ export type GenerateCodeOptions = {
isProject: boolean;
};

export type ActionGeneratedCallback = (event: IpcRendererEvent, actions: ActionContext[]) => void;
export type ActionGeneratedListener = (event: IpcRendererEvent, actions: ActionContext[]) => void;
export type TestEventListener = (event: IpcRendererEvent, data: TestEvent) => void;
export interface IElectronAPI {
exportScript: (string) => Promise<boolean>;
recordJourney: (url: string) => Promise<void>;
stopRecording: () => void;
pauseRecording: () => Promise<void>;
resumeRecording: () => Promise<void>;
addActionGeneratedListener(
callback: (event: IpcRendererEvent, actions: ActionContext[]) => void
): () => void;
addActionGeneratedListener(listener: ActionGeneratedListener): () => void;
generateCode: (params: GenerateCodeOptions) => Promise<string>;
openExternalLink: (url: string) => Promise<void>;
runTest: (
params: RunJourneyOptions,
callback: (event: IpcRendererEvent, data: TestEvent) => void
) => Promise<void>;
runTest: (params: RunJourneyOptions, listener: TestEventListener) => Promise<void>;
removeOnTestListener: () => void;
}
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ import { StyledComponentsEuiProvider } from './contexts/StyledComponentsEuiProvi
import { ExportScriptFlyout } from './components/ExportScriptFlyout';
import { useRecordingContext } from './hooks/useRecordingContext';
import { StartOverWarningModal } from './components/StartOverWarningModal';
import { ActionContext, RecorderSteps, Steps } from '../common/types';
import type { IpcRendererEvent } from 'electron';
import { ActionGeneratedListener, RecorderSteps, Steps } from '../common/types';

/**
* This is the prescribed workaround to some internal EUI issues that occur
Expand Down Expand Up @@ -85,7 +84,7 @@ export default function App() {

useEffect(() => {
// `actions` here is a set of `ActionInContext`s that make up a `Step`
const listener = (_event: IpcRendererEvent, actions: ActionContext[]) => {
const listener: ActionGeneratedListener = (_event, actions) => {
setSteps((prevSteps: RecorderSteps) => {
const nextSteps: Steps = generateIR([{ actions }]);
return generateMergedIR(prevSteps, nextSteps);
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useSyntheticsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import { IpcRendererEvent } from 'electron';
import { useCallback, useContext, useEffect, useReducer, useState } from 'react';
import { getCodeFromActions, getCodeForFailedResult } from '../common/shared';
import { CommunicationContext } from '../contexts/CommunicationContext';
import type { RecorderSteps, Result, TestEvent } from '../../common/types';
import type { RecorderSteps, Result, TestEventListener } from '../../common/types';
import type { ITestContext } from '../contexts/TestContext';
import { resultReducer } from '../helpers/resultReducer';

Expand Down Expand Up @@ -60,7 +59,7 @@ export function useSyntheticsTest(steps: RecorderSteps): ITestContext {
if (!isTestInProgress) {
// destroy stale state
dispatch({ data: undefined, event: 'override' });
const onTestEvent = (_event: IpcRendererEvent, data: TestEvent) => {
const onTestEventListener: TestEventListener = (_event, data) => {
dispatch(data);
};

Expand All @@ -71,7 +70,7 @@ export function useSyntheticsTest(steps: RecorderSteps): ITestContext {
code,
isProject: false,
},
onTestEvent
onTestEventListener
);
setIsTestInProgress(true);
setIsResultFlyoutVisible(true);
Expand Down

0 comments on commit 58b2ee5

Please sign in to comment.