PDA

View Full Version : Can I override Store's constructor or component's initComponent()?



ssamayoa
7 Mar 2012, 4:00 PM
I just updated my Designer to build 309. Apart for some minor glitches is working and there is the new feature to create override class.

Can I override Store's constructor or component's initComponent()?

I need to populate some store with a list of years like:



Ext.define('AutoGestion.store.override.Anos', {
requires: 'AutoGestion.store.Anos'
}, function() {
Ext.override(AutoGestion.store.Anos, {
constructor : function(cfg) {
cfg.data = [{ano: 2007, nombre: '2007'}];
this.callOverridden(cfg);
}
});
alert("override1");
});


But new constructor code isnt invoked...

Some example please...

Regards.

aconran
7 Mar 2012, 7:31 PM
This works fine in Sencha Touch 2.0.0. There is a bug in Sencha Touch 2 < Beta 3 that causes the override to not be loaded before the application launches.

It appears the same bug also appears in 4.0.2a. Will investigate further what it takes to fix this in Ext JS 4.0.x.

ssamayoa
7 Mar 2012, 8:31 PM
It appears the same bug also appears in 4.0.2a.

FWIW I replaced 4.0.2a with 4.0.7 in my application and got the same result. :(

I'm using Chrome 16.0.912.63 m in Windows 7.

Regards.

ssamayoa
8 Mar 2012, 6:35 AM
UPDATE:
overriding initComponent() works!

Overriding constructor() doesn't.

Both tested with Ext 4.0.7.

Regards.

aconran
8 Mar 2012, 8:52 AM
We're aware of the problems with Ext JS and are working to address them.

This technique works fine in Touch.

ssamayoa
8 Mar 2012, 9:40 AM
We're aware of the problems with Ext JS and are working to address them.

This technique works fine in Touch.

Yep, you already said that.

I tried a different approach for "year combo": I wrote a custom component overriding initComponent() + some custom properties so the final result was better: YearComboBox component which I can use anywhere in my application. I also wrote a MonthComboBox (which I need in several views in my application) thanks for the override mechanism.

That problem (constructor override) forced me to think different and the final result was better.

Regards.

bseddon
8 Mar 2012, 10:58 AM
I may be missing the specificity of your scenario however overloading a store constructor when using 4.0.7 works in my case. Here's an example I'm using right now in order to be able to apply a url resolved through the use of a function, something which is not permitted in the designer:


Ext.define('Photos.store.override.Images', { requires: 'Photos.store.Images'
}, function() {
Ext.override(Photos.store.Images, {
constructor: function(cfg)
{
console.log(Ext.String.format('Images: {0}', Ext.photosThumbService));
this.callOverridden(cfg);
this.getProxy().url = Ext.photosThumbService;
}
});
});

A difference is that I'm grabbing the proxy after it's been assigned by the super's constructor and then changing the url. Maybe a similar approach (setting the data variable explicitly rather than via config settings) would work for you?

ssamayoa
8 Mar 2012, 11:23 AM
Maybe a similar approach (setting the data variable explicitly rather than via config settings) would work for you?

Nope.
The problem I have is that the overriden constructor is never called.
I tried with 4.0.1, 4.0.2 and 4.0.7.

I throwed the code and used a different approach (creating the store in component's initComponent() method) but definitely I will give a try later.

Regards.

corcoranp
9 Mar 2012, 7:00 AM
I've run into the same issue. I have a store for which I already have data for and wanted to set the data property before the store gets a concrete implementation. I ran down the issue, and it's all about timing.

Basically, the store that I'm overloading is referenced in a view that is creating the store BEFORE, the overload is is applied.

I'm using:
Sencha Designer Version 2.0.0 Build: 309 RC: 2.0-beta
with
Ext 4.0.7

I've been able resolve this by editing the Designer generated code after deployment, but that's been a bit of a pain. I'm going to try overloading the initComponent and see if I get a different result! Thanks!

It would be nice if you could set properties of an object in the designer to a user-defined variable...

Cheers!

BTW...I think this is my first post since Jack owned this...

ssamayoa
9 Mar 2012, 7:57 AM
I've run into the same issue. I have a store for which I already have data for and wanted to set the data property before the store gets a concrete implementation. I ran down the issue, and it's all about timing.


Oh!

That explains the odd behaviour.

Thanks for the information.