Synchronously loading warning when using a template

Get help with testing, discuss unit testing strategies etc.
Post Reply
User avatar
Howard
Premium Member
Premium Member
Posts: 108
Joined: Tue Nov 29, 2016 2:05 pm

Synchronously loading warning when using a template

Post by Howard » Tue Oct 22, 2019 12:18 pm

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:

Code: Select all

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:

Code: Select all

[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?

User avatar
nickolay
Core Developer
Core Developer
Posts: 3382
Joined: Mon May 16, 2011 10:48 am

Re: Synchronously loading warning when using a template

Post by nickolay » Tue Oct 22, 2019 9:39 pm

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.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

User avatar
Howard
Premium Member
Premium Member
Posts: 108
Joined: Tue Nov 29, 2016 2:05 pm

Re: Synchronously loading warning when using a template

Post by Howard » Thu Oct 24, 2019 9:31 am

Hi Nickolay,

Thanks for the reply. I'm afraid I don't understand. My tests are started by

Code: Select all

project.startFromUrl
with a reference to a JSON file. This file then contains:

Code: Select all

[{
	"url": "unit/column/MyCol.t.js",
	"alsoPreload": [
		{
			"url": "../app/view/column/MyCol.js"
		}
	]
}]
How do I move the define into the startTest?

User avatar
nickolay
Core Developer
Core Developer
Posts: 3382
Joined: Mon May 16, 2011 10:48 am

Re: Synchronously loading warning when using a template

Post by nickolay » Thu Oct 24, 2019 9:37 am

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:

Code: Select all

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.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

Post Reply