From d71a1d103ea6f09992e27667e57123db4debc29d Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Wed, 28 Aug 2024 08:51:01 -0700 Subject: [PATCH] mention api --- .../best_practices/dev_experience.ipynb | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/examples/how_to/best_practices/dev_experience.ipynb b/examples/how_to/best_practices/dev_experience.ipynb index df1a914ef6..4212a437d8 100644 --- a/examples/how_to/best_practices/dev_experience.ipynb +++ b/examples/how_to/best_practices/dev_experience.ipynb @@ -582,7 +582,7 @@ "source": [ "#### Wrong\n", "\n", - "Modifying container objects by index will not trigger the callback." + "Modifying container `objects` by index will not trigger the callback." ] }, { @@ -607,6 +607,39 @@ "source": [ "col.objects[0] = [\"c\"] # does not trigger" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Good\n", + "\n", + "However, you **can** modify the container by index using the APIs on the component itself." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def print_objects(event):\n", + " print(f\"Got new {[pane.object for pane in event.new]}\")\n", + "\n", + "col = pn.Column(\"a\", \"b\")\n", + "pn.bind(print_objects, col.param.objects, watch=True)\n", + "col" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# col.objects[0] = 'Foo' # no\n", + "col[0] = 'Foo' # yes" + ] } ], "metadata": {