julioromano
02/05/2021, 4:37 PMBasicTextField
whose onValueChange
does two things:
1. Feeds `onValueChange`’s value back to the BasicTextField
to display what the user has typed.
2. Triggers an HTTP search call to fetch updated data to be displayed.
I’d like to debounce 2. but not 1. but: since the onValueChange
is a single callback I see no “easy” way to do it.
Were I to debounce the whole onValueChange
callback, the user will notice a lag with the on screen feedback too.
I believe this is a pretty common use case so I’m wondering if there’s a compose friendly pattern to handle this or if something ad-hoc must be concocted.Zach Klippenstein (he/him) [MOD]
02/05/2021, 5:01 PMjulioromano
02/05/2021, 5:04 PMSe7eN
02/05/2021, 5:26 PMonValueChange = {
value = it
debounce(value)
}
Zach Klippenstein (he/him) [MOD]
02/05/2021, 5:33 PMI thought this kind of debouncing should happen at the earliest possible in the “chain” which in this case is in the UI layer (though this is debatable of course).Why? You’ve described a very good reason why not to do this. Another reason is responsibility – if the same view model were used with different UI, the same debouncing logic would probably need to be applied. If that logic is in the UI layer like you propose, then you’d have to duplicate/rewrite it. It would also probably be a lot easier to unit test the debouncing logic if it’s in your view model.
julioromano
02/05/2021, 5:43 PMEditText
manages its own internal state I could always debounce it on the UI side using afterTextCange
without affecting the text fed back to the UI.Zach Klippenstein (he/him) [MOD]
02/05/2021, 5:53 PM