Page 1 of 1

Synchronously loading warning when using a template

Posted: Tue Oct 22, 2019 12:18 pm
by Howard
Hello,

We've got a bit of an issue with synchronously loading when a classes tpl config is using Ext.create. Given something like the following:
Ext.define('MyApp.column.MyCol', {
    extend: 'Ext.grid.column.Column',
    
    requires: ['MyApp.template.MyTemplate'],
    
    editor: {
        tpl: Ext.create('MyApp.template.MyTemplate')
    }
});
When I run a test which creates this column siesta will give the following warning:
[W] [Ext.Loader] Synchronously loading 'MyApp.template.MyTemplate'; consider adding Ext.require('MyApp.template.MyTemplate') above Ext.onReady
Even though it's already required. I think this may be something to do with it executing the Ext.create when it's parsing the markup before the requires can be assessed. Is there any way of structuring a test so that this no longer gives a warning?

Re: Synchronously loading warning when using a template

Posted: Tue Oct 22, 2019 9:39 pm
by nickolay
Hi,

Hm.. Yes, the warning is probably from there. Do you have the `Ext.define()` call at the top-level scope of the test file? Moving it inside the `StartTest()` scope should fix this I think.

Re: Synchronously loading warning when using a template

Posted: Thu Oct 24, 2019 9:31 am
by Howard
Hi Nickolay,

Thanks for the reply. I'm afraid I don't understand. My tests are started by
project.startFromUrl
with a reference to a JSON file. This file then contains:
[{
	"url": "unit/column/MyCol.t.js",
	"alsoPreload": [
		{
			"url": "../app/view/column/MyCol.js"
		}
	]
}]
How do I move the define into the startTest?

Re: Synchronously loading warning when using a template

Posted: Thu Oct 24, 2019 9:37 am
by nickolay
I thought you are defining the `MyCol` in the test file itself, but its in the separate file.

Actually, looking on the `MyCol`, the warning is valid:
Ext.define('MyApp.column.MyCol', {
    extend: 'Ext.grid.column.Column',
    
    requires: ['MyApp.template.MyTemplate'],
    
    editor: {
        tpl: Ext.create('MyApp.template.MyTemplate')
    }
});
Here you create an instance of the `MyApp.template.MyTemplate` at the time of the `Ext.define('MyApp.column.MyCol'` call. The loading, that is initiated by the `requires: ['MyApp.template.MyTemplate']` is asynchronous, so, the only way to create that instance is to load the class synchronously, hence the warning. To avoid the warning, you need to `Ext.create('MyApp.template.MyTemplate')` at some later point, inside the constructor for example.