I have main classic application "MyApp":
app.json contains:
"namespace": "NS",
....
"requires": [
"font-awesome",
"SubApp"
],
Inside this app I have a package "SubApp".
it's package.json:
"namespace": "SubApp",
....
"requires": []
I need SubApp to use MyApp classes, but when I try like this:
Ext.define('SubApp.view.Window',{
extend:'Ext.window.Window',
title: 'SubApp Window',
requires: ['MyApp.view.main.Primary'],
browser show an error:
Error: [Ext.create] Unrecognized class name / alias: MyApp.view.main.Primary
If I'll do this in browser console, it works good.
How to use parent applications classes from package?
This is a race-condition:
In the app you require a package and in the package you require the app.
Internally - while building with Sencha CMD - we grab all requires from the classes. It starts inside the App and finds a require for the package (100% correct) and then it heads over to the package to find all requires. Now it finds the App and tries to order the View higher than the required package.
During runtime it loads the package and tries to find the required view, but it's not yet there.
The solution is, to use uses
intead of requires
in the package.
Ext.define('SubApp.view.Window',{
extend:'Ext.window.Window',
title: 'SubApp Window',
uses: ['MyApp.view.main.Primary'],
Uses ensures, that a files gets added to the build process.
Basically it says: At the time when window gets created, the file has to be loaded.