Jump to content

HandleEvent question


GerhardV

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Administrators

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..

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

  • Administrators

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.

Link to comment
Share on other sites

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."

Link to comment
Share on other sites

  • Administrators

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...