Documentation for what is available in cb_obj and cb_data etc

In CustomJS callbacks, it is suggested to use cb_obj, cb_data etc. to communicate data from python code to javascript code. However, I searched around, but couldn’t find any documentation listing what is available from these communicators, is there a way to find the related information? Thanks.

From the very page you’ve linked to:

Additionally, the model that triggers the callback (i.e. the model that the callback is attached to) will be available as cb_obj .

Additionally, this section mentions both cb_obj and cb_data.

cb_data is indeed not very well document, I think mostly because it’s very model-specific. Sometimes the documentation of a particular model describes what you can expect to be in cb_data, sometimes not. A foolproof way to make sure is to read the source code. But backwards compatibility is not guaranteed of course.

I’m actually not sure cb_data is used for anything at all anymore. In the past it was a way to communicate selection geometries to callbacks on selection tools, but now there are proper events for selction geometries, and I don’t see anywhere that cb_data is set (from a quick search).

OK I spoke to soon, it’s definitely still used in a few places:

  • OpenURL apparently passes the CDS used

       32 :   execute(_cb_obj: unknown, {source}: {source: ColumnarDataSource}): void {
  • Web data sources (e.g. AjaxDataSouce) pass their HTTP responses

       45 :       data = adapter.execute(this, {response: raw_data})
  • Tap tools pass something (didn’t dig in to look)

       34 :           callback.execute(this.model, data)
       50 :           callback.execute(this.model, data)
  • Hover tools pass geometry (this old tool callback still exists, for this reason I guess)

     380 :       this.model.callback!.execute(this.model, {index, geometry: g, renderer: r})
  • Drop downs pass an index, no idea about this and would not rely on it

      105 :         value_or_callback.execute(this.model, {index: i}) // TODO