day8 / re-com

A ClojureScript library of reusable components for Reagent
https://re-com.day8.com.au
MIT License
797 stars 146 forks source link

Support async choices loading in single-dropdown #145

Closed nidu closed 7 years ago

nidu commented 7 years ago

Hello.

Can we add support of async choices loading to single-dropdown component? Here are some thoughts:

Description

Sometimes i need to load only portion of large data list. Probably i don't even want all this data outside the dropdown so don't wanna bother with fetching it around the list and updating on key press, so it could be convenient to embed this behavior into the component.

I suppose it doesn't need to use any external dependencies as using js setTimeout can be enough.

Why not just use typeahead? To me having two separate components for sync and async dropdowns looks inconsistent in both API and UI. Moreover single-dropdown have some great features like grouping.

UI

Async data load adds two features to UI:

Other than that UI is same. Async loader should return choices in same format as they are currently provided.

API

If :choices is not function all this async stuff is just skipped and dropdown works same way as of now.

Question: Alternatively :choices can operate with promises - would it be a nice choice considering that re-com doesn't strive for old browser support? Using callbacks is more universal and is enough here as for me.

Any thoughts about this? Maybe this task should be implemented differently?

UPD 1: here is an example implementation (see demo9 in dropdown demos).

Gregg8 commented 7 years ago

We've had a play with your fork and decided to merge it as is. We're fine with all your choices.

That's not to say it cannot continue to be further iterated.

Thanks for this!