Event Loop Demo

One problem that I used to have was duplicated forms showing up one above the other, caused by clicking on a button that would clear a column panel and load a form on it. While the form was loading, the user clicked on another link that did something similar. The clear of the second click comes before the load of the first is finished because the first is waiting on a server call. The result is:

  • click on button 1
  • clear column panel
  • start loading form1 on the column panel and wait for server call to return
  • click on button 2
  • clear column panel (which is already empty)
  • start loading form2 on the column panel and wait for server call to return
  • complete loading form1 or form2, whichever finishes its server call first, and add it to the column panel
  • complete loading the other form and add it to the column panel

At this point I have both form1 and form2. @stucork just mentioned this problem a few days ago: Quick navigation results in multiple components(forms) being added to the top-level page - #4

I used to use a context manager that would show a semi-transparent div above the whole page and prevent the user from interacting with any input element, something like:

def button_click(self, **e):
    with grayed_interface():
        self.container.clear()
        self.add_component(MyForm())

Then I started working with the routing module and the problem disappeared (thanks Stu!).

The routing module helps only during the navigation. The problem you are mentioning still exists with possible inconsistent data during normal interaction with the form, but it doesn’t bother me much, in fact I don’t even remember when was the last time I used that context manager (which doesn’t mean the problem doesn’t exists, it means I’m lazy and my users don’t complain enough for me to work on it).

2 Likes