]> khamidou — GitHub mirrors - electron.git/commitdiff
Detail ipc.removeListener & ipc.removeAllListeners
authorMing Luo <mcluo1994@gmail.com>
Wed, 13 Jan 2016 15:18:12 +0000 (10:18 -0500)
committerMing Luo <mcluo1994@gmail.com>
Wed, 13 Jan 2016 15:18:12 +0000 (10:18 -0500)
docs/api/ipc-main.md
docs/api/ipc-renderer.md

index bbaa3c0043f690862e888ac3fb06705919875b50..87430e7e99662410a3e12efea3405894ba5b6ccc 100644 (file)
@@ -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:
index 01f0bb3a83ddc262c8c329f09de241959f667eff..d88b477ea71475395aaaaa4e25f7a729fa0c522c 100644 (file)
@@ -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: