Skip to content

Commit

Permalink
refactor: onMessage -> onEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 26, 2022
1 parent bf2acd9 commit 4c65e3f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/guide/api-plugin.md
Expand Up @@ -544,7 +544,7 @@ if (import.meta.hot) {
}
```
On the plugin side, we can use `server.ws.onMessage` listening to the events:
On the plugin side, we can use `server.ws.onEvent` listening to the events:
```js
// vite.config.js
Expand All @@ -553,7 +553,7 @@ export default defineConfig({
{
// ...
configureServer(server) {
server.ws.onMessage('from-client', (data, client) => {
server.ws.onEvent('from-client', (data, client) => {
console.log('Message from client:', data.msg) // Hey!
// reply only to the client (if needed)
client.send({
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/hmr/vite.config.js
Expand Up @@ -19,7 +19,7 @@ module.exports = {
}
},
configureServer(server) {
server.ws.onMessage('remote-add', ({ a, b }, client) => {
server.ws.onEvent('remote-add', ({ a, b }, client) => {
client.send({
type: 'custom',
event: 'remote-add-result',
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/ws.ts
Expand Up @@ -32,7 +32,7 @@ export interface WebSocketServer {
/**
* Handle custom event emitted by `import.meta.hot.send`
*/
onMessage<T>(event: string, listener: WebSocketCustomListener<T>): () => void
onEvent<T>(event: string, listener: WebSocketCustomListener<T>): () => void
/**
* Listen to raw events from the WebSocket server.
* @advanced
Expand Down Expand Up @@ -217,7 +217,7 @@ export function createWebSocketServer(
})
},

onMessage<T>(event: string, listener: WebSocketCustomListener<T>) {
onEvent<T>(event: string, listener: WebSocketCustomListener<T>) {
if (!customListeners.has(event)) customListeners.set(event, new Set())
customListeners.get(event)!.add(listener)

Expand Down

0 comments on commit 4c65e3f

Please sign in to comment.