Jemt / Fit.UI

Fit.UI is a JavaScript based UI framework built on Object Oriented principles
http://fitui.org
GNU Lesser General Public License v3.0
19 stars 7 forks source link

WS controls - potential problems with async. data load #74

Closed FlowIT-JIT closed 5 years ago

FlowIT-JIT commented 5 years ago

WS controls expose a range of features that triggers data load. The following problems were revealed in a WSDropDown using a WSTreeView as picker to load data from a JSONP WebService returning partial data with some nodes having the "HasChildren" set to indicate that remote nodes are available and must be retrieve when node is expanded.

Data is loaded when:

Expanding nodes (programmatically or by user interaction) Invoking SelectAll(..) Invoking Reload(..) Invoking ExpandAll(..) Invoking EnsureData(..)

Old school nodes of call stacks to getData(..) image

It is not hard to imagine that a programmer may do something that triggers getData(..) multiple times.

Loads all data twice - dublicated nodes

wsTree.EnsureData();
wsTree.SelectAll(true);

Bug: Callback fired too early In this example the callback in ExpandAll(..) is triggered before all data is loaded, because the async. operation from EnsureData(..) interupts the logic in ExpandAll(..)

wsTree.EnsureData();
wsTree.ExpandAll(99999, function() { Fit.Controls.Dialog.Alert("DONE"); });

Variable behaviour Surprisingly, the code below works and does not trigger double data load:

wsTree.ExpandAll();
wsTree.SelectAll(true);

But if we reverse the order, data is loaded twice:

wsTree.SelectAll(true);
wsTree.ExpandAll();

Problem triggered in UI by user with a WSDropDown control hosting a WSTreeView picker In this case we imaging a slow WebService that takes seconds to load data.

  1. User opens dropdown control which triggers load of root nodes. An OnOpen event thandler is registered which calls sender.GetTreeView().EnsureData() to load all nodes - this is the second time data load is triggered.
  2. Before data is loaded, user triggers SelectAll via a ContextMenu. System starts loading data for the 3rd time.

What we probably need is for all operations that eventually end up triggering getData(..) - this is probably EnsureData, ExpandAll, Reload, SelectAll - is to queue those operations. Once data has finished loading, the operations are re-triggered. If all data is loaded, a new call to getData(..) is avoided (except for Reload of course which must always discard and reload data), and the given operation is executed.

FlowIT-JIT commented 5 years ago

These issues have now been resolved in WSTreeView, WSListView, WSDropDown, and WSContextMenu. They are now "thread safe". Operations resulting in WebService requests are now executed sequentially and in the proper order.

If multiple operations resulting in WebService requests are triggered, they are moved to a process queue from where they are executed sequentially once WebService communication has completed.

Related commits:

faf041a48ac0109620e4a4b1f00e4edc57d9b00e 2ae749f076c99bce2c848b02cbc84fd37065a33f cb9865d804e86538ea0ce8e3fecc9d38a4755251