Detail ipc.removeListener & ipc.removeAllListeners
This commit is contained in:
parent
489539d62e
commit
a82ecfda06
2 changed files with 55 additions and 6 deletions
|
@ -1,8 +1,10 @@
|
|||
# ipcRenderer
|
||||
|
||||
The `ipcRenderer` module provides a few methods so you can send synchronous and
|
||||
asynchronous messages from the render process (web page) to the main process.
|
||||
You can also receive replies from the main process.
|
||||
The `ipcRenderer` module is an instance of the
|
||||
[EventEmitter](https://nodejs.org/api/events.html) class. It provides a few
|
||||
methods so you can send synchronous and asynchronous messages from the render
|
||||
process (web page) to the main process. You can also receive replies from the
|
||||
main process.
|
||||
|
||||
See [ipcMain](ipc-main.md) for code examples.
|
||||
|
||||
|
@ -18,6 +20,29 @@ The `ipcRenderer` module has the following method to listen for events:
|
|||
When the event occurs the `callback` is called with an `event` object and
|
||||
arbitrary arguments.
|
||||
|
||||
Once done listening for messages, if you longer want to activate this callback
|
||||
and for whatever reason can't merely stop sending messages on the channel, you
|
||||
can use:
|
||||
|
||||
### `ipcRenderer.removeListener(channel, callback)`
|
||||
|
||||
* `channel` String - The event name.
|
||||
* `callback` Function - The reference to the same function that you used for
|
||||
`ipcRenderer.on(channel, callback)`
|
||||
|
||||
Alternatively, if you don't have access to the same callback, you can use:
|
||||
|
||||
### `ipcRenderer.removeAllListeners(channel)`
|
||||
|
||||
* `channel` String - The event name.
|
||||
|
||||
This has the expected effect of removing *all* handlers to this ipc channel.
|
||||
|
||||
Because of this class' inheritance from the `EventEmitter` node class, you can
|
||||
also use `ipcRenderer.once(channel, callback)` to fire handlers meant to occur only
|
||||
once, as in, they won't be activated after one call of `callback`
|
||||
|
||||
|
||||
## Sending Messages
|
||||
|
||||
The `ipcRenderer` module has the following methods for sending messages:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue