Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debouncing action dispatching #117

Open
jordond opened this issue Apr 25, 2019 · 1 comment
Open

Debouncing action dispatching #117

jordond opened this issue Apr 25, 2019 · 1 comment

Comments

@jordond
Copy link
Contributor

jordond commented Apr 25, 2019

This is less of an issue, and more asking for an opinion. I've run into a use-case where I need to debounce the dispatching of an action. For example a user is entering text into a search box, which updates a property on the state, which then launches a async network request.

You wouldn't want it to send a request every time a character is typed, but rather after some delay.

Currently I am using a Timer in the Fragment, the approach is simple and it works. I'm just wondering if it's worth coming up with an EiffelViewModel solution.

@etiennelenhart
Copy link
Owner

That's definitely something that would be useful.

I'd probably go for an eiffel-ui module that provides extension functions for common Android view listeners, since debouncing seems like something the dispatching side should take care of.

The new Flow type from Kotlin Coroutines seems like a good fit, since they're already working on UI-related operators. (Kotlin/kotlinx.coroutines#1107)

So the extensions could expect an EiffelViewModel and an Action as parameters, internally add the required listener that pushes updates to a debounced Flow channel and dispatch the given action on each emit.

That's still a bit rough, especially considering that the Flow API isn't stable yet and documentation is currently scarce, but it could work.

I'm not sure whether something similar is planned for Anko as this would be a good fit but haven't found any information on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants