Skip to content

Commit

Permalink
feat(ipcman): support getMethod()
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp committed Mar 3, 2024
1 parent b1725ce commit caba523
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/devtools-fe/src/components/timeline/table/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ export const TextCell: FC<{
)
}

export const PreCell: FC<{
children: string
}> = ({ children }) => {
return (
<div
className={
children ? styles.textCellContainer : styles.textCellContainerEmpty
}
>
<div className={children ? styles.textCell : styles.textCellEmpty}>
<pre children={children} />
</div>
</div>
)
}

export const HeaderCell: FC<{
children: string
}> = ({ children }) => (
Expand Down
7 changes: 4 additions & 3 deletions packages/devtools-fe/src/components/timeline/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { Dispatch, FC, MouseEvent, SetStateAction } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import type { IpcManItem } from '../../../services/remote'
import { useRemote } from '../../../services/remote'
import { HeaderCell, IndexCell, TextCell, TypeCell } from './cell'
import { HeaderCell, IndexCell, PreCell, TextCell, TypeCell } from './cell'
import styles from './index.module.scss'

const columnHelper = createColumnHelper<IpcManItem>()
Expand Down Expand Up @@ -50,10 +50,11 @@ const columns = [
cell: (info) => <TextCell children={info.getValue()} />,
},
),
columnHelper.accessor('data.channel', {
columnHelper.accessor((x) => `${x.data.channel}\n${x.data.method || ''}`, {
id: 'channel',
size: 160,
header: () => <HeaderCell children="Channel / Method" />,
cell: (info) => <TextCell children={info.getValue()} />,
cell: (info) => <PreCell children={info.getValue()} />,
}),
columnHelper.accessor(
(x) => (x.data.requestArgs ? JSON.stringify(x.data.requestArgs) : ''),
Expand Down
8 changes: 8 additions & 0 deletions packages/ipcman/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type IpcSender<IpcArgs extends unknown[] = unknown[]> = (

export interface IpcManDataBase {
channel: string
method: string | undefined
args: unknown[]
}

Expand Down Expand Up @@ -72,6 +73,7 @@ type Awaitable<T> = T | Promise<T>
export interface IpcManConfig<IpcArgs extends unknown[] = unknown[]> {
handler: (data: IpcManData) => Awaitable<unknown>
getId?: (p: IpcArgs) => string | undefined
getMethod?: (p: IpcArgs) => string | undefined
}

export interface IpcManContext {
Expand Down Expand Up @@ -106,13 +108,15 @@ export const ipcMan = <IpcArgs extends unknown[] = unknown[]>(
config.handler({
type: 'wrapped-response',
channel,
method: config.getMethod?.(e as IpcArgs),
args: e,
id,
})
else
config.handler({
type: 'event',
channel,
method: config.getMethod?.(e as IpcArgs),
args: e,
})
}
Expand All @@ -125,13 +129,15 @@ export const ipcMan = <IpcArgs extends unknown[] = unknown[]>(
config.handler({
type: 'wrapped-request',
channel: eventName as string,
method: config.getMethod?.(p),
args: p,
id,
})
else
config.handler({
type: 'request',
channel: eventName as string,
method: config.getMethod?.(p),
args: p,
})

Expand All @@ -146,6 +152,7 @@ export const ipcMan = <IpcArgs extends unknown[] = unknown[]>(
config.handler({
type: 'handle-request',
channel: method,
method: config.getMethod?.(args as IpcArgs),
args,
id,
})
Expand All @@ -155,6 +162,7 @@ export const ipcMan = <IpcArgs extends unknown[] = unknown[]>(
config.handler({
type: 'handle-response',
channel: method,
method: config.getMethod?.(args as IpcArgs),
args: [result],
id,
})
Expand Down

0 comments on commit caba523

Please sign in to comment.