I’m trying to use multiple Applications inside one parent Application.
Here is example fiddle like this:
Ext.application({
name : 'Parent app',
launch : function() {
Ext.application({
name: 'ChildApp1',
sayHello: function(){
console.log('ChildApp 1');
}
});
Ext.application({
name: 'ChildApp2',
sayHello: function(){
console.log('ChildApp 2');
}
});
But when I’m trying to interact between apps, it seems that last App rewrites whole primary namespace.
I am trying to dynamically access a specific App, but I get only the App created last.
const appName = 'ChildApp1';
Ext.app.Application.instance.getApplication(appName).sayHello(); // calls ChildApp2 method
How is it possible to dynamicly call (I don’t know app name in advance) multiple applications methods from each other ?
Am I right with classes architecture/definition or not?
2
Answers
I managed to figure out this issue by rewriting Ext.application to class definitions extending Ext.app.Application like this:
Now you can call various apps methods like this:
Here is fiddle.
Also you can read some interesting information in old sencha forum thread.
From what I see in your fiddle you could use a workspace with packages. It does not look like you are really using 2 Ext Applications. Unfortunately fiddle does not support custom packages.
Create a workspace
https://docs.sencha.com/cmd/7.7.0/guides/workspaces.html
sencha generate workspace /path/to/workspace
Create a Package
With a workspace you can add packages:
https://docs.sencha.com/cmd/7.7.0/guides/cmd_packages/cmd_packages.html
sencha generate package common
Dynamic Package Loading
With packages you can use dynamic package loading:
https://docs.sencha.com/cmd/7.7.0/guides/dynamic_package_loading.html
Explanation
A package can be a supplier of functionality, views, data, …
A package can be build just like an application, but you can bundle or import it with your main application.
Example Usecase
base
package, and require it for all your apps. This basically loads functionality.