Skip to content

Commit

Permalink
mention api
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 committed Aug 28, 2024
1 parent 86b4f15 commit d71a1d1
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion examples/how_to/best_practices/dev_experience.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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": {
Expand Down

0 comments on commit d71a1d1

Please sign in to comment.