PDA

View Full Version : Understaning common code



TampaBay55
21 Jul 2015, 10:32 AM
Greetings all:

I have some javascript files that will be used for all the apps in my workspace. I am not certain how to include the code in the app I am working with. I placed the files in the "packages" folder in the workspace folder but sencha cmd tells me the file cannot be found on an app refresh. Is there some documentation pointing to how I include common code in all my workspace apps? Thanks.

***UPDATE

I have created sencha package using the sencha cmd generate package command. I placed the source code in the package's src folder and included in the app.json as indicated. I am still getting 404 errors - the class could not be located:

My app.json:



/*** The list of required packages (with optional versions; default is "latest").
*
* For example,
*
* "requires": [
* "charts"
* ]
*/
"requires": [
"font-awesome",
"AltGlobalLib"
],

In my main app:

Ext.define('Login.Application', {
extend: 'Ext.app.Application',
name: 'Login',
launch: function () {
CpsWebApp = this;
cp = Ext.supports.LocalStorage == false ? Ext.create('Ext.state.CookieProvider') : Ext.create('Ext.state.LocalStorageProvider');
Ext.state.Manager.setProvider(cp);
CpsGlobal = CpsWebApp.getController('AltGlobalLib'); <===
}
});

In the packages/local/src folder (AltGlobalLib.js):

Ext.define('AltGlobalLib',{
extend: 'Ext.app.Controller',
... Bunch of methods

TampaBay55
22 Jul 2015, 3:34 AM
*** Another Update ***

Created a sencha package called "Common" and placed a file in the package src folder called "globallib.js" which contained a controller:


Ext.define('Common.GlobalLib',{
extend: 'Ext.app.Controller',
...bunch of methods here...
})

The app.json file for my application contains an entry like this:

"requires": [
"font-awesome",
"Common"
],

The application.js file looks like this:

Ext.define('Login.Application', {
extend: 'Ext.app.Application',
name: 'Login',
namespaces: ['Common'],
requires: ['Common.GlobalLib'],
launch: function () {
CpsWebApp = this;
cp = Ext.supports.LocalStorage == false ? Ext.create('Ext.state.CookieProvider') : Ext.create('Ext.state.LocalStorageProvider');
Ext.state.Manager.setProvider(cp);
CpsGlobal = CpsWebApp.getController('Common.GlobalLib');
}
});

It does appear the the controller Common.GlobalLib is loading fine but I receive a warning in the console:

[W] Missing namespace for Common.GlobalLib, please define it in namespaces property of your Application class.
I have changed the namespaces to what was suggested in the warning but I still get the warning. Am I still missing a step here?? Thanks.

TampaBay55
24 Jul 2015, 8:51 AM
*Bump* please.

mitchellsimoens
28 Jul 2015, 7:00 AM
Why aren't you defining Common.GlobalLib as a controller in your Application class? Something like this:


controllers : [
'[email protected]'
]

Also, I see you are using global variables. The industry looks down on global variables for they can cause memory leaks so try to avoid them using other techniques to cache references.

TampaBay55
28 Jul 2015, 7:24 AM
Hey Mitchell:

Honestly, I didn't know that's how it was supposed to be done. Where is the documentation for how to define these entities?

I was toying with the globals just trying to figure out how to do these includes. I wouldn't typically use global variables in an application. I do appreciate the help. Thank you.

TB55