Transforms the given kwargs to a dict suitable for calling this callback. Mirrors how the Dash renderer assembles the callback payload — see ``fillVals()`` in ``dash-renderer/src/actions/callbacks.ts``. For pattern-matching callbacks, wildcard deps are expanded into
(self, kwargs: dict[str, Any])
| 64 | ) |
| 65 | |
| 66 | def as_callback_body(self, kwargs: dict[str, Any]) -> CallbackExecutionBody: |
| 67 | """Transforms the given kwargs to a dict suitable for calling this callback. |
| 68 | |
| 69 | Mirrors how the Dash renderer assembles the callback payload — |
| 70 | see ``fillVals()`` in ``dash-renderer/src/actions/callbacks.ts``. |
| 71 | |
| 72 | For pattern-matching callbacks, wildcard deps are expanded into |
| 73 | nested arrays with concrete component IDs. |
| 74 | """ |
| 75 | raw_inputs = self._cb_info.get("inputs", []) |
| 76 | raw_state = self._cb_info.get("state", []) |
| 77 | n_deps = len(raw_inputs) + len(raw_state) |
| 78 | |
| 79 | flat_values = [None] * n_deps |
| 80 | for i, name in enumerate(self._param_names): |
| 81 | if i < n_deps and name in kwargs: |
| 82 | flat_values[i] = kwargs[name] |
| 83 | |
| 84 | inputs_with_values = [ |
| 85 | _expand_dep(dep, flat_values[i]) for i, dep in enumerate(raw_inputs) |
| 86 | ] |
| 87 | state_with_values = [ |
| 88 | _expand_dep(dep, flat_values[len(raw_inputs) + i]) |
| 89 | for i, dep in enumerate(raw_state) |
| 90 | ] |
| 91 | |
| 92 | outputs_spec = _expand_output_spec( |
| 93 | self._output_id, self._cb_info, inputs_with_values |
| 94 | ) |
| 95 | |
| 96 | # changedPropIds: only inputs with non-None values. |
| 97 | # This determines ctx.triggered_id in the callback. |
| 98 | changed = [] |
| 99 | for entry in inputs_with_values: |
| 100 | if isinstance(entry, dict) and entry.get("value") is not None: |
| 101 | eid = entry.get("id") |
| 102 | if isinstance(eid, dict): |
| 103 | changed.append( |
| 104 | f"{json.dumps(eid, sort_keys=True)}.{entry['property']}" |
| 105 | ) |
| 106 | elif isinstance(eid, str): |
| 107 | changed.append(f"{eid}.{entry['property']}") |
| 108 | |
| 109 | return { |
| 110 | "output": self._output_id, |
| 111 | "outputs": outputs_spec, |
| 112 | "inputs": inputs_with_values, |
| 113 | "state": state_with_values, |
| 114 | "changedPropIds": changed, |
| 115 | } |
| 116 | |
| 117 | # ------------------------------------------------------------------- |
| 118 | # Public identity and metadata |
no test coverage detected