Search Support
-
Pavan KumarJanuary 23, 2020 at 1:33 am #5637
Hi Team,
Which way is good to write custom functions interns of code maintenance ,readability, usage of available API etc?
1. custom HTML – access everything using page.ui
2. inside inline js in CV
3. inside inline events of controls like onclick,onchange etc.(the same can be called by a function which is in inline js or custom html)Most of the times i observe salient/spark team uses page.ui.get(in customHTML i think) to get the things done. so is it preferred way of doing ? But writing lot of code in custom html will lead to slowness of UI loading.
Kindly throw some inputs. Thanks in advance
SPARK SupportJanuary 23, 2020 at 6:55 am #5638Hi Pavan,
The answer to this really comes down to the complexity of the development. Personally, I use page.ui for troubleshooting in the console or developing code with a live coach. For simple implementations, code in the control events may be sufficient. However, if the code is more than one line, I write functions in the Inline JS and reference those functions from the control events. If a custom coach view becomes complex enough, and especially if it is a repeated view such as a custom control, the best practice is to save a JS file as a server file and load the JS file on the view.
Regards,
Stephen P
Pavan KumarJanuary 23, 2020 at 10:27 pm #5641Thanks for reply Stephen.
Agreed.
Please clarify below.
If we pass the controlId/bpmext/any other addition parameters like data/file etc through function the scope of those is valid in inline JS ?
Can i do some thing like below? can i access all the methods available for text control and bpmext in inline js function ?
—code in on click of button —
var nameControlId =${Text1}; –Text control in CV
var BPEXT = bpmext;
view.testFunction(nameControlId , BPEXT );
–function in inline JS—
this.testFunction = function(nameControlId , BPEXT ){
console.log( nameControlId.getData() )
}
SPARK SupportJanuary 24, 2020 at 7:24 am #5642Hi Pavan,
Yes, those are valid references to pass. However, I tend to get references to controls from within the Coach View function by using this.ui.get(“/containerPath/controlName”). And, all functions of bpmext should already be available to the “this” reference in later BAW versions, such as the aforementioned this.ui.get();
Regards,
Stephen P
Pavan KumarJanuary 24, 2020 at 7:25 pm #5643Hi Stephen,
using exact path of ui control “/containerPath/controlName” approach will make it tightly coupled with UI design. If any changes to UI design in future will require re check of path of controls mentioned in our code. Would like to know your view on this.?
Pavan KumarJanuary 27, 2020 at 6:23 am #5644Hi Stephen,
I am unable to see bpmext functions in coachview ”this”. Could you please help me how to get in CV?
Thanks in advance.
Pavan KumarJanuary 27, 2020 at 6:52 am #5645Hi Stephen,
able to access bpmext in CV in BAWv19.
Can you please clarify below.
using exact path of ui control “/containerPath/controlName” approach will make it tightly coupled with UI design. If any changes to UI design in future will require re check of path of controls mentioned in our code. Would like to know your view on this.?
SPARK SupportJanuary 27, 2020 at 2:53 pm #5647Hi Pavan,
One pattern you can use to keep functions associated with a custom Coach View is to create getters and setters like standard object oriented programming. Add a function to Nested_Coach_View1 such as this.setControlData = function(dataValue). Then use this.ui.get(“controlName”).setData(dataValue) within that function. Then from the parent Coach View, use this.ui.get(“Nested_Coach_View1 “).setControlData(dataValue) to call the function on the inner view.
The trade off here is that you will be able to reuse the nested coach view, but have to code the methods to set the values on each parent view where the nested view is reused.
Regards,
Stephen P
-
|
You must be logged in to reply to this topic.