Skip to content

Commit a82ecfd

Browse files
committed
Detail ipc.removeListener & ipc.removeAllListeners
1 parent 489539d commit a82ecfd

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

docs/api/ipc-main.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# ipcMain
22

3-
The `ipcMain` module, when used in the main process, handles asynchronous and
4-
synchronous messages sent from a renderer process (web page). Messages sent from
5-
a renderer will be emitted to this module.
3+
The `ipcMain` module is an instance of the
4+
[EventEmitter](https://nodejs.org/api/events.html) class. When used in the main
5+
process, it handles asynchronous and synchronous messages sent from a renderer
6+
process (web page). Messages sent from a renderer will be emitted to this
7+
module.
68

79
## Sending Messages
810

@@ -54,6 +56,28 @@ The `ipcMain` module has the following method to listen for events:
5456
When the event occurs the `callback` is called with an `event` object and a
5557
message, `arg`.
5658

59+
Once done listening for messages, if you longer want to activate this callback
60+
and for whatever reason can't merely stop sending messages on the channel, you
61+
can use:
62+
63+
### `ipcMain.removeListener(channel, callback)`
64+
65+
* `channel` String - The event name.
66+
* `callback` Function - The reference to the same function that you used for
67+
`ipcMain.on(channel, callback)`
68+
69+
Alternatively, if you don't have access to the same callback, you can use:
70+
71+
### `ipcMain.removeAllListeners(channel)`
72+
73+
* `channel` String - The event name.
74+
75+
This has the expected effect of removing *all* handlers to this ipc channel.
76+
77+
Because of this class' inheritance from the `EventEmitter` node class, you can
78+
also use `ipcMain.once(channel, callback)` to fire handlers meant to occur only
79+
once, as in, they won't be activated after one call of `callback`
80+
5781
## IPC Event
5882

5983
The `event` object passed to the `callback` has the following methods:

docs/api/ipc-renderer.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# ipcRenderer
22

3-
The `ipcRenderer` module provides a few methods so you can send synchronous and
4-
asynchronous messages from the render process (web page) to the main process.
5-
You can also receive replies from the main process.
3+
The `ipcRenderer` module is an instance of the
4+
[EventEmitter](https://nodejs.org/api/events.html) class. It provides a few
5+
methods so you can send synchronous and asynchronous messages from the render
6+
process (web page) to the main process. You can also receive replies from the
7+
main process.
68

79
See [ipcMain](ipc-main.md) for code examples.
810

@@ -18,6 +20,29 @@ The `ipcRenderer` module has the following method to listen for events:
1820
When the event occurs the `callback` is called with an `event` object and
1921
arbitrary arguments.
2022

23+
Once done listening for messages, if you longer want to activate this callback
24+
and for whatever reason can't merely stop sending messages on the channel, you
25+
can use:
26+
27+
### `ipcRenderer.removeListener(channel, callback)`
28+
29+
* `channel` String - The event name.
30+
* `callback` Function - The reference to the same function that you used for
31+
`ipcRenderer.on(channel, callback)`
32+
33+
Alternatively, if you don't have access to the same callback, you can use:
34+
35+
### `ipcRenderer.removeAllListeners(channel)`
36+
37+
* `channel` String - The event name.
38+
39+
This has the expected effect of removing *all* handlers to this ipc channel.
40+
41+
Because of this class' inheritance from the `EventEmitter` node class, you can
42+
also use `ipcRenderer.once(channel, callback)` to fire handlers meant to occur only
43+
once, as in, they won't be activated after one call of `callback`
44+
45+
2146
## Sending Messages
2247

2348
The `ipcRenderer` module has the following methods for sending messages:

0 commit comments

Comments
 (0)