docs: clarify example in message-channel-main (#25625)

This commit is contained in:
Jeremy Rose 2020-09-28 10:58:32 -07:00 committed by GitHub
parent fd63510ca9
commit ac25f4d2ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,9 +13,19 @@ Process: [Main](../glossary.md#main-process)
Example: Example:
```js ```js
// Main process
const { port1, port2 } = new MessageChannelMain() const { port1, port2 } = new MessageChannelMain()
w.webContents.postMessage('port', null, [port2]) w.webContents.postMessage('port', null, [port2])
port1.postMessage({ some: 'message' }) port1.postMessage({ some: 'message' })
// Renderer process
const { ipcRenderer } = require('electron')
ipcRenderer.on('port', (e) => {
// e.ports is a list of ports sent along with this message
e.ports[0].on('message', (messageEvent) => {
console.log(messageEvent.data)
})
})
``` ```
### Instance Properties ### Instance Properties