Adds an event to the component's dependencies. Parameters: event_name: event name fn: Callable function inputs: input list outputs: output list preprocess: whether to run the preprocess methods of components pos
(
self,
event_name: str,
fn: Callable | None,
inputs: Component | List[Component] | Set[Component] | None,
outputs: Component | List[Component] | None,
preprocess: bool = True,
postprocess: bool = True,
scroll_to_output: bool = False,
show_progress: bool = True,
api_name: AnyStr | None = None,
js: str | None = None,
no_target: bool = False,
queue: bool | None = None,
batch: bool = False,
max_batch_size: int = 4,
cancels: List[int] | None = None,
every: float | None = None,
)
| 134 | ) |
| 135 | |
| 136 | def set_event_trigger( |
| 137 | self, |
| 138 | event_name: str, |
| 139 | fn: Callable | None, |
| 140 | inputs: Component | List[Component] | Set[Component] | None, |
| 141 | outputs: Component | List[Component] | None, |
| 142 | preprocess: bool = True, |
| 143 | postprocess: bool = True, |
| 144 | scroll_to_output: bool = False, |
| 145 | show_progress: bool = True, |
| 146 | api_name: AnyStr | None = None, |
| 147 | js: str | None = None, |
| 148 | no_target: bool = False, |
| 149 | queue: bool | None = None, |
| 150 | batch: bool = False, |
| 151 | max_batch_size: int = 4, |
| 152 | cancels: List[int] | None = None, |
| 153 | every: float | None = None, |
| 154 | ) -> Dict[str, Any]: |
| 155 | """ |
| 156 | Adds an event to the component's dependencies. |
| 157 | Parameters: |
| 158 | event_name: event name |
| 159 | fn: Callable function |
| 160 | inputs: input list |
| 161 | outputs: output list |
| 162 | preprocess: whether to run the preprocess methods of components |
| 163 | postprocess: whether to run the postprocess methods of components |
| 164 | scroll_to_output: whether to scroll to output of dependency on trigger |
| 165 | show_progress: whether to show progress animation while running. |
| 166 | api_name: Defining this parameter exposes the endpoint in the api docs |
| 167 | js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components |
| 168 | no_target: if True, sets "targets" to [], used for Blocks "load" event |
| 169 | batch: whether this function takes in a batch of inputs |
| 170 | max_batch_size: the maximum batch size to send to the function |
| 171 | cancels: a list of other events to cancel when this event is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. |
| 172 | Returns: None |
| 173 | """ |
| 174 | # Support for singular parameter |
| 175 | if isinstance(inputs, set): |
| 176 | inputs_as_dict = True |
| 177 | inputs = sorted(inputs, key=lambda x: x._id) |
| 178 | else: |
| 179 | inputs_as_dict = False |
| 180 | if inputs is None: |
| 181 | inputs = [] |
| 182 | elif not isinstance(inputs, list): |
| 183 | inputs = [inputs] |
| 184 | |
| 185 | if isinstance(outputs, set): |
| 186 | outputs = sorted(outputs, key=lambda x: x._id) |
| 187 | else: |
| 188 | if outputs is None: |
| 189 | outputs = [] |
| 190 | elif not isinstance(outputs, list): |
| 191 | outputs = [outputs] |
| 192 | |
| 193 | if fn is not None and not cancels: |
no test coverage detected