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

Debounce column sorting #6

Open
Chris-Petty opened this issue Apr 10, 2017 · 2 comments
Open

Debounce column sorting #6

Chris-Petty opened this issue Apr 10, 2017 · 2 comments

Comments

@Chris-Petty
Copy link
Contributor

Currently if a user spams the sorting on a column, it'll stack up the function calls and slowly (for lots of rows), sequentially run each sort call.

Idea is to debounce the function given to onPress, so that repeated presses don't make repeated calls. This should be done in a way that respects RN component state. Need to think about how long to make the delay and whether or not it is a prop to the table component (I like the idea of making it proportional to the amount of rows).

An optimisation would be to have row data array simply reversed if only isAscending is changed.

As an aside, it would be good to indicate that the sorting is running. A small loading indicator or animation should communicate this to the user. Could replace the sort arrow with a spinner until complete, or dim/overlay the table with a loading spinner in the middle while it sorts.

msupply-foundation/mobile#412

@Chris-Petty Chris-Petty added enhancement Priority: normal Bug or feature but has work around labels Apr 10, 2017
@Chris-Petty Chris-Petty added Pure/Virtualised list rewrite Priority: normal Bug or feature but has work around and removed Priority: normal Bug or feature but has work around labels Jul 8, 2019
@josh-griffin
Copy link

Adding a library might be a little heavy-handed, but underscore has a lot of helpful features anyway. Anyway, simple solution could be to make a TouchableDebounce component, wrapping a Touchable and it's onPress prop with https://underscorejs.org/#debounce

@Chris-Petty
Copy link
Contributor Author

I hear Lodash is cooler than underscore 😛.

It's tempting just to take the underscore implementation and paste it in. It's just about a dozen lines as seen here. Saves having to deal with the dependancy? If I'm not mistaken, we can make sure the build we publish does the correct tree shaking and then the dependancy will be reduced to just debounce anyway. Copy paste sure sounds easier though!

Lodash for data array processing optimisations is probs something to consider, though. If this repo ends up with any of that.

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