Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f09225

Browse files
committed
feat: add webviewApi export
1 parent e55ee57 commit 1f09225

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/vscode-webview/src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type PostMessageListener<T> = (data: T) => void | Promise<void>;
3535
* The vscode api for post message
3636
*/
3737
class VSCodeWebview {
38-
private readonly webviewApi: WebviewApi<unknown> | undefined;
38+
private readonly webviewApi: WebviewApi<any> | undefined;
3939
private _options: PostMessageOptions = {
4040
interval: INTERVAL,
4141
timeout: TIMEOUT,
@@ -138,10 +138,19 @@ class VSCodeWebview {
138138
});
139139
}
140140

141+
/**
142+
* Register a listener for a message type
143+
* @param type the message type
144+
* @param listener the listener
145+
*/
141146
on<T>(type: string, listener: PostMessageListener<T>) {
142147
this.listeners.set(type, listener);
143148
}
144149

150+
/**
151+
* Remove a listener for a message type
152+
* @param type the message type
153+
*/
145154
off(type: string) {
146155
this.listeners.delete(type);
147156
}
@@ -151,7 +160,7 @@ class VSCodeWebview {
151160
*
152161
* @return The current state or `undefined` if no state has been set.
153162
*/
154-
async getState(): Promise<any> {
163+
async getState<T = any>(): Promise<T> {
155164
return this.webviewApi?.getState();
156165
}
157166

@@ -170,6 +179,11 @@ class VSCodeWebview {
170179
}
171180

172181
/**
173-
* the vscode webview api
182+
* The vscode webview api
174183
*/
175184
export const vscodeWebview = new VSCodeWebview();
185+
186+
/**
187+
* The vscode webview api
188+
*/
189+
export const webviewApi = vscodeWebview;

0 commit comments

Comments
 (0)