Skip to content

Commit 3bce568

Browse files
authored
Merge pull request #4374 from mlucool/patch-1
Improve comms.rst example
2 parents 7ded638 + e8163d5 commit 3bce568

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/source/comms.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ containing Javascript to connect to it.
6565

6666
.. code-block:: python
6767
68-
def target_func(comm, msg):
68+
def target_func(comm, open_msg):
6969
# comm is the kernel Comm instance
7070
# msg is the comm_open message
7171
7272
# Register handler for later messages
7373
@comm.on_msg
7474
def _recv(msg):
7575
# Use msg['content']['data'] for the data in the message
76+
comm.send({'echo': msg['content']['data']})
7677
77-
# Send data to the frontend
78+
# Send data to the frontend on creation
7879
comm.send({'foo': 5})
7980
8081
get_ipython().kernel.comm_manager.register_target('my_comm_target', target_func)
@@ -87,8 +88,7 @@ And then open the comm from the frontend:
8788

8889
.. code-block:: javascript
8990
90-
comm = Jupyter.notebook.kernel.comm_manager.new_comm('my_comm_target',
91-
{'foo': 6})
91+
const comm = Jupyter.notebook.kernel.comm_manager.new_comm('my_comm_target', {'foo': 6})
9292
// Send data
9393
comm.send({'foo': 7})
9494

0 commit comments

Comments
 (0)