on 03-17-2019 11:39 AM
Hi SAP UI5 community,
In my project structure, we have multiple controller files for multiple views. We have a common util.js file with functions to handle the common functionality for all the views. Currently in each controller, I am loading all the library dependencies using the sap.ui.define statement. Even when there are some common dependencies among all controllers, these dependencies are present in each of the controller.js files (in sap.ui.define).
1) Since the views are loaded one after the other, Does UI5 internally take care of loading those dependencies declared in multiple controllers only once?
say first controller.js has - sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/apimgmt/ui/analyticsNextGen/utils/vizFrame","sap/m/Table")]....
second controller.js also has - sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/m/Table")]....
Is the sap.m.Table loaded in UI5 only once? When UI5 encounters it for the second time in second controller.js, does it return the library export value alone (without loading it again)?
2) In the common util.js file we have, I will still have to use UI5 libraries to create common SAP UI5 tables etc. Hence I am using sap.ui.require to get the instances of already loaded exports to work with the same -
var Table = sap.ui.require("sap/m/Table");
var oTable = new Table({});
Is this a correct approach of doing the same?
Or is there a way in which I could use the sap.ui.define statement to load the libraries in this common util.js file which is not a controller? (Note that the functions in this util.js file would be called from the controller files)
My intention is to load the libraries only once so as to make my application performance efficient.
1. Yes, it is loaded once
2. Why not use `sap.ui.define` insteads of sap.ui.require, so that we are consistent in loading libraries?
Maybe you can provide a small snippet on why you cannot use sap.ui.define
thanks
Dennis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dennis,
Here's the code snippet as requested -
controller.js -
sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/m/Table","util"], function(Controller, Table, util){
"use strict";
return Controller.extend("controller.Overview", {
refresh : function(oEvent){
createTable();
}
});
util.js -(contains various functions as shown below which are called from controller.js)
var createTable = function(){
var Table = sap.ui.require("sap/m/Table");//returns the export of already loaded library from controller.
---
return Table;
}
var func2 = function(){
}
util.js can be written as
sap.ui.define("sap/m/Table", function(Table) {
return {
createTable: function() {
var Table = new Table();
...
return Table;
},
func2: function () {
...
}
};
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sap.ui.define(["sap/m/Table"], function(Table){
"use strict";
return {
createTable:function(){},
function2:function(){}
};
}
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.