GerhardV Posted November 11, 2016 Posted November 11, 2016 Hi Farshad: I was playing around, thinking about a design to minimize network traffic, when I noticed the following whilst having the Chrome Debug Console open. I basically have a panel that is collapsible to the left. I noticed that every time I would collapse or expand the panel it would send an AjaRequest to the server (handleEvent) even though nothing is assigned to the OnCollapse or OnExpand events in Delphi. Below is the temporary code that UniGUI generated for this. O22C.on("collapse", function () { ajaxRequest(O22C, "collapse", ["w=" + O22C.getWidth(), "h=" + O22C.getHeight()]) }); O22C.on("expand", function () { ajaxRequest(O22C, "expand", ["w=" + O22C.getWidth(), "h=" + O22C.getHeight()]) }); Now I might be wrong or maybe don't fully understand the design but could we not maybe cut down on network traffic in this case by not generating any code for an AjaxRequest if no "Event" code for OnCollapse or OnExpand were assigned? If this holds true then it can have a huge impact on performance, especially with a significant number of users. Is there any other places where this logic can be applied as well? Quote
GerhardV Posted November 11, 2016 Author Posted November 11, 2016 I have done some further investigation and made some changes to the "InitCollapseEvents" method for TUniCustomPanel. procedure TUniCustomPanel.InitCollapseEvents; begin if Assigned(FOnCollapse) then JSCall('on','"collapse",function(){ajaxRequest('#1',"collapse",["w="+'#1'.getWidth(),"h="+'#1'.getHeight()])}'); if Assigned(FOnExpand) then JSCall('on','"expand",function(){ajaxRequest('#1',"expand",["w="+'#1'.getWidth(),"h="+'#1'.getHeight()])}'); end; It seems to work and no AjaxRequest is sent to the server if there is no event handler assigned in the Delphi code. The question now is....will this have side effects that I am not aware of? It also seems that an AjaxRequest is sent when dragging the panel but I am unable to locate the code that generates the EndDrag event. Quote
Administrators Farshad Mohajeri Posted November 11, 2016 Administrators Posted November 11, 2016 Hi, Those events are sent to the server to inform it about changes in size and layout, so server can recalculate the Align and Anchor rules and re-position controls if needed. To reduce traffic you can switch to Client Side Alignment approach instead of using default Server Side approach.. Quote
GerhardV Posted November 11, 2016 Author Posted November 11, 2016 Thanks Farshad but actually everything is using Client Side alignment, that was the first thing I checked as that was my suspicion, unless I miss something. But what you are also saying is that we need another check and that is to check "AlignmentControl = uniAlignmentServer"? BTW the EndDrag event I was looking for might be in the uniGUIClasses file which we don't seem to have the source for. procedure TUniCustomPanel.InitCollapseEvents; begin {We only want to send these events when alignment is controlled by the server} if ((AlignmentControl = uniAlignmentServer) or Assigned(FOnCollapse)) then JSCall('on','"collapse",function(){ajaxRequest('#1',"collapse",["w="+'#1'.getWidth(),"h="+'#1'.getHeight()])}'); if ((AlignmentControl = uniAlignmentServer) or Assigned(FOnExpand)) then JSCall('on','"expand",function(){ajaxRequest('#1',"expand",["w="+'#1'.getWidth(),"h="+'#1'.getHeight()])}'); end; Quote
Administrators Farshad Mohajeri Posted November 11, 2016 Administrators Posted November 11, 2016 Thanks Farshad but actually everything is using Client Side alignment, that was the first thing I checked as that was my suspicion, unless I miss something. But what you are also saying is that we need another check and that is to check "AlignmentControl = uniAlignmentServer"? BTW the EndDrag event I was looking for might be in the uniGUIClasses file which we don't seem to have the source for. Maybe there is a bug in uniPanel code. I will check and inform you. Quote
Administrators Farshad Mohajeri Posted November 11, 2016 Administrators Posted November 11, 2016 Yes, there was a bug in UniPanel code. Events are generated even in Client side alignment mode. Quote
GerhardV Posted November 14, 2016 Author Posted November 14, 2016 Farshad thanks for the fix in 1343 but did you also fix the EndDrag event? Quote
Administrators Farshad Mohajeri Posted November 14, 2016 Administrators Posted November 14, 2016 Farshad thanks for the fix in 1343 but did you also fix the EndDrag event? Whats wrong with EndDrag event? Quote
GerhardV Posted November 15, 2016 Author Posted November 15, 2016 Same thing happens when dragging the panel and there is nothing assigned to the OnEndDrag event. "It also seems that an AjaxRequest is sent when dragging the panel but I am unable to locate the code that generates the EndDrag event." Quote
Administrators Farshad Mohajeri Posted November 15, 2016 Administrators Posted November 15, 2016 Same thing happens when dragging the panel and there is nothing assigned to the OnEndDrag event. "It also seems that an AjaxRequest is sent when dragging the panel but I am unable to locate the code that generates the EndDrag event." It is used internally to inform server about new X,Y position of the control. Quote
GerhardV Posted November 15, 2016 Author Posted November 15, 2016 Thanks Farshad I see, but I am still not sure why it is necessary. I am trying to think of a use case other than when an event handler is assigned. I see TUniPanel inherits from TUniCustomContainerPanel which is declared in UniGUIClasses but we don't have the source for that. I wanted to see the logic implemented around that. Will you make the source code available for that? Quote
GerhardV Posted November 16, 2016 Author Posted November 16, 2016 Farshad, will you make the source code available for UniGUIClasses? Quote
Administrators Farshad Mohajeri Posted November 16, 2016 Administrators Posted November 16, 2016 Farshad, will you make the source code available for UniGUIClasses? It is a part of uniGUI Core library which we can not make public yet. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.