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

Skip to content

Commit 0d4fc90

Browse files
committed
feat: export wrapper class and remove instances
1 parent 0b8a4df commit 0d4fc90

File tree

3 files changed

+142
-69
lines changed

3 files changed

+142
-69
lines changed

packages/vscode-webview/README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# @tomjs/vscode-webview
22

3-
[![npm](https://img.shields.io/npm/v/@tomjs/vscode-webview)](https://www.npmjs.com/package/@tomjs/vscode-webview) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vscode-webview) ![NPM](https://img.shields.io/npm/l/@tomjs/vscode-webview) [![Docs](https://img.shields.io/badge/API-unpkg-orange)](https://www.unpkg.com/browse/@tomjs/vscode-webview/dist/index.d.ts)
3+
[![npm](https://img.shields.io/npm/v/@tomjs/vscode-webview)](https://www.npmjs.com/package/@tomjs/vscode-webview) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vscode-webview) ![NPM](https://img.shields.io/npm/l/@tomjs/vscode-webview) [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@tomjs/vscode-webview)
44

55
**English** | [中文](./README.zh_CN.md)
66

77
> Optimize the postMessage issue between webview page and vscode extension
88
9-
When developing extensions using `webview`, there will be communication-related issues. This project provides communication solutions between `webview` and extension. If [@tomjs/vite-plugin-vscode](https://github.com/tomjs/vite-plugin-vscode) is used during the development phase, there will be delay issues due to intermediate forwarding.
9+
Wrapped the official [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) and added some methods.
1010

1111
## Install
1212

@@ -23,42 +23,60 @@ npm add @tomjs/vscode-webview
2323

2424
## Documentation
2525

26+
- [API Document](https://www.jsdocs.io/package/@tomjs/vscode-webview) provided by [jsdocs.io](https://www.jsdocs.io).
2627
- [index.d.ts](https://www.unpkg.com/browse/@tomjs/vscode-webview/dist/index.d.ts) provided by [unpkg.com](https://www.unpkg.com).
2728

2829
## Usage
2930

30-
### vscodeWebview.postAndReceiveMessage(type, message, options): Promise<any>
31+
### vscodeWebview.getState()
3132

32-
Send and receive messages
33+
Get the persistent state stored for this webview.
34+
35+
### vscodeWebview.setState(state)
36+
37+
Set the persistent state stored for this webview.
38+
39+
### vscodeWebview.postMessage(message)
40+
41+
Post a message to the owner of the webview
42+
43+
### vscodeWebview.post(type, message, options)
44+
45+
Send message
3346

3447
- type: message type
3548
- message: message content
3649
- options: configuration items
3750

38-
### vscodeWebview.postMessage(type, message, options)
51+
### vscodeWebview.postAndReceive(type, message, options): Promise<any>
3952

40-
Send message
53+
Send and receive messages
4154

4255
- type: message type
4356
- message: message content
57+
- options: configuration items
4458

45-
### vscodeWebview.on(type, listener)
59+
### vscodeWebview.on(type, success[, fail])
4660

4761
Listen for messages
4862

4963
- type: message type
50-
- listener: listener callback function
64+
- success: listener success callback function
65+
- fail: listener error callback function
5166

5267
### vscodeWebview.off(type)
5368

5469
Cancel listening for messages
5570

5671
- type: message type
5772

58-
### vscodeWebview.getState():Promise<any>
73+
## Important Notes
5974

60-
Get the persistent state stored for this webview.
75+
### v2.0.0
6176

62-
### vscodeWebview.setState(state: any): any
77+
**Breaking Updates:**
6378

64-
Set the persistent state stored for this webview.
79+
- Export the `WebviewApiWrapper` class that wraps `WebviewApi`
80+
- Modify the `postMessage` method to be consistent with the method of the `WebviewApi` instance
81+
- Change the original `postMessage` and `postAndReceiveMessage` method names to `post` and `postAndReceive`
82+
- Delete the `WebviewApiWrapper` instances: `vscodeWebview` and `webviewApi`, which need to be manually introduced and instantiated
Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# @tomjs/vscode-webview
22

3-
[![npm](https://img.shields.io/npm/v/@tomjs/vscode-webview)](https://www.npmjs.com/package/@tomjs/vscode-webview) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vscode-webview) ![NPM](https://img.shields.io/npm/l/@tomjs/vscode-webview) [![Docs](https://img.shields.io/badge/API-unpkg-orange)](https://www.unpkg.com/browse/@tomjs/vscode-webview/dist/index.d.ts)
3+
[![npm](https://img.shields.io/npm/v/@tomjs/vscode-webview)](https://www.npmjs.com/package/@tomjs/vscode-webview) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vscode-webview) ![NPM](https://img.shields.io/npm/l/@tomjs/vscode-webview) [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@tomjs/vscode-webview)
44

55
[English](./README.md) | **中文**
66

77
> 优化 webview 页面与 vscode 扩展的 postMessage 问题
88
9-
使用 `webview` 开发扩展,会有通讯相关的问题,本项目提供了 `webview` 和 扩展的通讯解决方案。如果使用了 [@tomjs/vite-plugin-vscode](https://github.com/tomjs/vite-plugin-vscode) 开发阶段,由于中间转发,会有延时的问题
9+
对官方的 [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) 进行了封装并增加了一些方法
1010

1111
## 安装
1212

@@ -23,42 +23,60 @@ npm add @tomjs/vscode-webview
2323

2424
## 文档
2525

26+
- [jsdocs.io](https://www.jsdocs.io) 提供的 [API Document](https://www.jsdocs.io/package/@tomjs/vscode-webview).
2627
- [unpkg.com](https://www.unpkg.com/) 提供的 [index.d.ts](https://www.unpkg.com/browse/@tomjs/vscode-webview/dist/index.d.ts).
2728

2829
## 使用
2930

30-
### vscodeWebview.postAndReceiveMessage(type, message, options): Promise<any>
31+
### vscodeWebview.getState(): any
3132

32-
发送并接收消息
33+
获取此 webview 存储的持久状态。
34+
35+
### vscodeWebview.setState(state: any): any
36+
37+
设置此 webview 存储的持久状态。
38+
39+
### vscodeWebview.postMessage(message:any)
40+
41+
向 WebView 的所有者发布消息
42+
43+
### vscodeWebview.post(type, message, options)
44+
45+
发送消息
3346

3447
- type: 消息类型
3548
- message: 消息内容
3649
- options: 配置项
3750

38-
### vscodeWebview.postMessage(type, message, options)
51+
### vscodeWebview.postAndReceive(type, message, options): Promise<any>
3952

40-
发送消息
53+
发送并接收消息
4154

4255
- type: 消息类型
4356
- message: 消息内容
57+
- options: 配置项
4458

45-
### vscodeWebview.on(type, listener)
59+
### vscodeWebview.on(type, success[, fail])
4660

4761
监听消息
4862

4963
- type: 消息类型
50-
- listener: 监听回调函数
64+
- success: 监听成功回调函数
65+
- fail: 监听失败回调函数
5166

5267
### vscodeWebview.off(type)
5368

5469
取消监听消息
5570

5671
- type: 消息类型
5772

58-
### vscodeWebview.getState():Promise<any>
73+
## 重要说明
5974

60-
获取此 webview 存储的持久状态。
75+
### v2.0.0
6176

62-
### vscodeWebview.setState(state: any): any
77+
**破坏性更新:**
6378

64-
设置此 webview 存储的持久状态。
79+
- 导出 `WebviewApi` 的封装 `WebviewApiWrapper`
80+
- `postMessage` 方法修改为与 `WebviewApi` 实例的方法一致
81+
-`postMessage``postAndReceiveMessage` 方法名改为 `post``postAndReceive`
82+
- 删除 `WebviewApiWrapper` 的实例:`vscodeWebview``webviewApi`,需要手动引入并实例化

0 commit comments

Comments
 (0)