Is there a way to have an intent be cancelled if a...
# orbit-mvi
j
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
The way i solve this issues, is creating a throttle/debounce operation before calling the intent
I don’t believe this is responsibility of the intent mechanism
j
You mean you do the throttle/debounce in the UI layer instead of in the view model?
g
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
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
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.
👌 1