Is there a way to have an intent be cancelled if another call to the intent comes in after it starts running? I am implementing a search text field and finding that it will execute a lot of requests.
g
Guilherme Delgado
01/19/2024, 4:20 PM
The way i solve this issues, is creating a throttle/debounce operation before calling the intent
Guilherme Delgado
01/19/2024, 4:22 PM
I don’t believe this is responsibility of the intent mechanism
j
Jacob Rhoda
01/19/2024, 4:27 PM
You mean you do the throttle/debounce in the UI layer instead of in the view model?
g
Guilherme Delgado
01/19/2024, 4:30 PM
In this case yes (in the compose screen) but you could move it to the VM also, it will depend on your UX. The idea is to call the intent only after the operation concludes
a
agrosner
01/23/2024, 1:00 AM
You could also make a flow that debounces when called, and that collects within an intent . The calling function will call this. Flow instead of intent directly
j
Jacob Rhoda
01/23/2024, 3:25 AM
I actually did just that. I made a new state value flow and have that one debounced and collected in an intent that is started when the container initializes… When the user types, the value goes into that state flow. It also tracks it in the container state separately so there’s still a single source of truth for the UI.