remi icon indicating copy to clipboard operation
remi copied to clipboard

DropDown and ListView APIs compared

Open fpp-gh opened this issue 9 years ago • 3 comments

Davide, as discussed in Gitter, here are a couple of remarks/questions about my experience so far. Below is a side-by-side comparison of the bare APIs for ListView and Dropdown :

class ListView(Widget, _SyncableValuesMixin): class DropDown(Widget, _SyncableValuesMixin):
def __init__(self, selectable=True, **kwargs): def__init__(self, **kwargs):
def new_from_list(cls, items, **kwargs): def new_from_list(cls, items, **kwargs):
def append(self, item, key=''): def append(self, item, key=''):
def empty(self): def empty(self):
def onselection(self, widget): def onchange(self, value):
*def set_on_selection_listener(self, callback, userdata): *def set_on_change_listener(self, callback, userdata):
prototype listener :
my_list_onselection(self, widget, selectedKey)
prototype listener :
my_dropdown_onchange(self, widget, value)
def get_value(self): def get_value(self):
def get_key(self): def get_key(self):
def select_by_key(self, key): def select_by_key(self, key):
def set_value(self, value): def set_value(self, value):
def select_by_value(self, value): def select_by_value(self, value):

One can see that they are almost identical, which is perfectly sensible: these widgets are almost twins, have the same uses and data types, and they differ only in their display. Actually, what surprises me is that they are not exactly the same :-)

Is there a good reason (technical or otherwise) to have different on-keywords and listener-setting methods ? And worse yet, for the listeners themselves to have different prototypes ? (the one for dropdown is more user-friendly than that for listview :-)

If not, I would argue that it would be easier for new users (all users, actually) if both APIs were perfectly identical. Myself I started my prototype with two listviews, then wanted to changed to dropdowns just to see what suited the UI best... So I just changed the two constructor calls, and was very surprised when it didn't work :-)

fpp-gh avatar Oct 29 '16 16:10 fpp-gh

@fpp-gh There is a technical reason for this. ListView listens and propagates ListItems in its events. The DropDown instead manages 'strings' in its events. You may ask why. This is because ListView is based on html's 'ul' tag, DropDown is based on html's 'select' instead. They differs on javascript events.

dddomodossola avatar Oct 31 '16 17:10 dddomodossola

Okay, got that, thanks.

So does the REMI internal plumbing make it impossible for you to mask these differences, and show a common user-level API for the two widgets ?...

fpp-gh avatar Nov 01 '16 10:11 fpp-gh

REMI could paper over these differences and present a coherent API, but such differences exist throughout the library. It's a cost/benefit decision.

Also, onselection and onchange should be considered private. They should really be named something like _js_onselection as they are private callbacks from the javascript client code. There are many things in remi that should be private but are not expressed as such.

nzjrs avatar Nov 01 '16 12:11 nzjrs