From: Ming Luo Date: Wed, 13 Jan 2016 15:18:12 +0000 (-0500) Subject: Detail ipc.removeListener & ipc.removeAllListeners X-Git-Tag: v0.36.4~7^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a82ecfda06aaeb9d2861f7b1ed7bb0198159a4ca;p=electron.git Detail ipc.removeListener & ipc.removeAllListeners --- diff --git a/docs/api/ipc-main.md b/docs/api/ipc-main.md index bbaa3c00..87430e7e 100644 --- a/docs/api/ipc-main.md +++ b/docs/api/ipc-main.md @@ -1,8 +1,10 @@ # ipcMain -The `ipcMain` module, when used in the main process, handles asynchronous and -synchronous messages sent from a renderer process (web page). Messages sent from -a renderer will be emitted to this module. +The `ipcMain` module is an instance of the +[EventEmitter](https://nodejs.org/api/events.html) class. When used in the main +process, it handles asynchronous and synchronous messages sent from a renderer +process (web page). Messages sent from a renderer will be emitted to this +module. ## Sending Messages @@ -54,6 +56,28 @@ The `ipcMain` module has the following method to listen for events: When the event occurs the `callback` is called with an `event` object and a message, `arg`. +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: + +### `ipcMain.removeListener(channel, callback)` + +* `channel` String - The event name. +* `callback` Function - The reference to the same function that you used for + `ipcMain.on(channel, callback)` + +Alternatively, if you don't have access to the same callback, you can use: + +### `ipcMain.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 `ipcMain.once(channel, callback)` to fire handlers meant to occur only +once, as in, they won't be activated after one call of `callback` + ## IPC Event The `event` object passed to the `callback` has the following methods: diff --git a/docs/api/ipc-renderer.md b/docs/api/ipc-renderer.md index 01f0bb3a..d88b477e 100644 --- a/docs/api/ipc-renderer.md +++ b/docs/api/ipc-renderer.md @@ -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: