viewAction
Passing message between the command view and the command view action.
The viewAction
has two types of communications sync
and async
. sync
is for one-way communication and async
is for two-way communication.
Functions
communicationType.sendMessage
communicationType.sendMessage(…args: unknown[]): unknown
To send message between the view and the view action.
Example
communicationType.on
communicationType.on(listener: (…args: unknown[]) => unknown): void
Listen or handle the message.
You must only use one listener per event for the async
type. If an async
event has multiple listeners, it will use the latter.
Example
communicationType.off
communicationType.on(listener: (…args: unknown[]) => unknown): void
Remove the event listener.
Event Types
If you’re using TypeScript and want to add typing for the ‘viewAction’ events. First, you need to create a .d.ts
file. You can put this file inside the ‘types’ folder in the project root, for example, types/global.d.ts
. And inside that file add ExtensionViewActionAsyncEvent
and ExtensionViewActionSyncEvent
interfaces.