Skip to content

Commit b8e8e4c

Browse files
committed
docs: Cleanup the IPC docs
1 parent 63578f9 commit b8e8e4c

File tree

3 files changed

+61
-53
lines changed

3 files changed

+61
-53
lines changed

docs/api/ipc-main.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.
99
## Sending Messages
1010

1111
It is also possible to send messages from the main process to the renderer
12-
process, see [webContents.send](web-contents.md#webcontentssendchannel-arg1-arg2-) for more information.
12+
process, see [webContents.send][web-contents-send] for more information.
1313

1414
* When sending a message, the event name is the `channel`.
1515
* To reply a synchronous message, you need to set `event.returnValue`.
@@ -48,37 +48,37 @@ ipcRenderer.send('asynchronous-message', 'ping');
4848

4949
The `ipcMain` module has the following method to listen for events:
5050

51-
### `ipcMain.on(channel, callback)`
51+
### `ipcMain.on(channel, listener)`
5252

53-
* `channel` String - The event name.
54-
* `callback` Function
53+
* `channel` String
54+
* `listener` Function
5555

56-
When the event occurs the `callback` is called with an `event` object and
57-
arbitrary arguments.
56+
Listens to `channel`, when a new message arrives `listener` would be called with
57+
`listener(event, args...)`.
5858

59-
### `ipcMain.removeListener(channel, callback)`
59+
### `ipcMain.once(channel, listener)`
6060

61-
* `channel` String - The event name.
62-
* `callback` Function - The reference to the same function that you used for
63-
`ipcMain.on(channel, callback)`
61+
* `channel` String
62+
* `listener` Function
6463

65-
Once done listening for messages, if you no longer want to activate this
66-
callback and for whatever reason can't merely stop sending messages on the
67-
channel, this function will remove the callback handler for the specified
68-
channel.
64+
Adds a one time `listener` function for the event. This `listener` is invoked
65+
only the next time a message is sent to `channel`, after which it is removed.
6966

70-
### `ipcMain.removeAllListeners(channel)`
67+
### `ipcMain.removeListener(channel, listener)`
7168

72-
* `channel` String - The event name.
69+
* `channel` String
70+
* `listener` Function
7371

74-
This removes *all* handlers to this ipc channel.
72+
Removes the specified `listener` from the listener array for the specified
73+
`channel`.
7574

76-
### `ipcMain.once(channel, callback)`
75+
### `ipcMain.removeAllListeners([channel])`
7776

78-
Use this in place of `ipcMain.on()` to fire handlers meant to occur only once,
79-
as in, they won't be activated after one call of `callback`
77+
* `channel` String (optional)
8078

81-
## IPC Event
79+
Removes all listeners, or those of the specified `channel`.
80+
81+
## Event object
8282

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

@@ -90,4 +90,6 @@ Set this to the value to be returned in a synchronous message.
9090

9191
Returns the `webContents` that sent the message, you can call
9292
`event.sender.send` to reply to the asynchronous message, see
93-
[webContents.send](web-contents.md#webcontentssendchannel-arg1-arg2-) for more information.
93+
[webContents.send][web-contents-send] for more information.
94+
95+
[web-contents-send]: web-contents.md#webcontentssendchannel-arg1-arg2-

docs/api/ipc-renderer.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,69 @@ See [ipcMain](ipc-main.md) for code examples.
1212

1313
The `ipcRenderer` module has the following method to listen for events:
1414

15-
### `ipcRenderer.on(channel, callback)`
15+
### `ipcRenderer.on(channel, listener)`
1616

17-
* `channel` String - The event name.
18-
* `callback` Function
17+
* `channel` String
18+
* `listener` Function
1919

20-
When the event occurs the `callback` is called with an `event` object and
21-
arbitrary arguments.
20+
Listens to `channel`, when a new message arrives `listener` would be called with
21+
`listener(event, args...)`.
2222

23-
### `ipcRenderer.removeListener(channel, callback)`
23+
### `ipcRenderer.once(channel, listener)`
2424

25-
* `channel` String - The event name.
26-
* `callback` Function - The reference to the same function that you used for
27-
`ipcRenderer.on(channel, callback)`
25+
* `channel` String
26+
* `listener` Function
2827

29-
Once done listening for messages, if you no longer want to activate this
30-
callback and for whatever reason can't merely stop sending messages on the
31-
channel, this function will remove the callback handler for the specified
32-
channel.
28+
Adds a one time `listener` function for the event. This `listener` is invoked
29+
only the next time a message is sent to `channel`, after which it is removed.
3330

34-
### `ipcRenderer.removeAllListeners(channel)`
31+
### `ipcRenderer.removeListener(channel, listener)`
3532

36-
* `channel` String - The event name.
33+
* `channel` String
34+
* `listener` Function
3735

38-
This removes *all* handlers to this ipc channel.
36+
Removes the specified `listener` from the listener array for the specified
37+
`channel`.
3938

40-
### `ipcRenderer.once(channel, callback)`
39+
### `ipcRenderer.removeAllListeners([channel])`
4140

42-
Use this in place of `ipcRenderer.on()` to fire handlers meant to occur only once,
43-
as in, they won't be activated after one call of `callback`
41+
* `channel` String (optional)
42+
43+
Removes all listeners, or those of the specified `channel`.
4444

4545
## Sending Messages
4646

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

4949
### `ipcRenderer.send(channel[, arg1][, arg2][, ...])`
5050

51-
* `channel` String - The event name.
51+
* `channel` String
5252
* `arg` (optional)
5353

54-
Send an event to the main process asynchronously via a `channel`, you can also
55-
send arbitrary arguments. Arguments will be serialized (json) and hence no functions or prototype chain will be included. The main process handles it by listening for the
56-
`channel` event with `ipcMain`.
54+
Send a message to the main process asynchronously via `channel`, you can also
55+
send arbitrary arguments. Arguments will be serialized in JSON internally and
56+
hence no functions or prototype chain will be included.
57+
58+
The main process handles it by listening for `channel` with `ipcMain` module.
5759

5860
### `ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])`
5961

60-
* `channel` String - The event name.
62+
* `channel` String
6163
* `arg` (optional)
6264

63-
Send an event to the main process synchronously via a `channel`, you can also
64-
send arbitrary arguments.
65+
Send a message to the main process synchronously via `channel`, you can also
66+
send arbitrary arguments. Arguments will be serialized in JSON internally and
67+
hence no functions or prototype chain will be included.
6568

66-
The main process handles it by listening for the `channel` event with
67-
`ipcMain` and replies by setting `event.returnValue`.
69+
The main process handles it by listening for `channel` with `ipcMain` module,
70+
and replies by setting `event.returnValue`.
6871

6972
__Note:__ Sending a synchronous message will block the whole renderer process,
7073
unless you know what you are doing you should never use it.
7174

7275
### `ipcRenderer.sendToHost(channel[, arg1][, arg2][, ...])`
7376

74-
* `channel` String - The event name.
77+
* `channel` String
7578
* `arg` (optional)
7679

7780
Like `ipcRenderer.send` but the event will be sent to the `<webview>` element in

docs/api/web-contents.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,11 @@ Opens the developer tools for the service worker context.
693693
* `arg` (optional)
694694

695695
Send an asynchronous message to renderer process via `channel`, you can also
696-
send arbitrary arguments. Arguments will be serialized (json) and hence no functions or prototype chain will be included. The renderer process can handle the message by
697-
listening to the `channel` event with the `ipcRenderer` module.
696+
send arbitrary arguments. Arguments will be serialized in JSON internally and
697+
hence no functions or prototype chain will be included.
698+
699+
The renderer process can handle the message by listening to `channel` with the
700+
`ipcRenderer` module.
698701

699702
An example of sending messages from the main process to the renderer process:
700703

0 commit comments

Comments
 (0)