PDA

View Full Version : Events and Mixins - Where to add things



Malte123
19 Jan 2014, 3:29 PM
Hello all :-)

I don't get really clear the right way to work with Event-System if it goes over more Instances of different Classes and also works with Mixins.

Here an possible Case:

Main.js


//: ...
afterRender: function(){
var service = Ext.widget('SpecialUxLibFassadeClass',{
pin: '0815',
cfg: 'FileToLoadByAjax'
}).on('fileReadyEvent', function(){
console.log('service');
console.log(service.uncryptedConfig);
})
}


SpecialUxLibFassadeClass.js


Ext.define('SpecialUxLibFassadeClass',{
extend: 'Ext.util.Observable',
mixins: {
SpecialUxLibFactory: 'Ext.ux....SpecialUxLibFactoryClass'
},
alias: 'widget.SpecialUxLibFassadeClass',
config:{
pin: '',
cfg: ''
},
uncryptedConfig: '',
constructor: function(config){
this.initConfig(config);
this.addEvents('uncrypted');
this.callParent(parameters);

this.mixins.SpecialUxLibFactory.addEvents('fileReadyEvent');
this.mixins.SpecialUxLibFactory.callParent(arguments);

this.uncryptedConfig = this.mixins.SpecialUxLibFactory.uncryptingMethod();
}
})


SpecialUxLibFactory.js


Ext.define('SpecialUxLibFactory',{
extend: 'Ext.util.Observable',
//:
//:
uncryptingMethod:function(){
// some code to decrypt
//:...
this.fireEventAfterUncryptedFileIsReady();
},
fireEventAfterUncryptedFileIsReady: function(){
this.fireEvent('fileReadyEvent');
}



Where and how to add the Listeners to make the Mixin able to fire the Event 'fileReadyEvent' and .on('fileReadyEvent'... can go forward ?

I tried:


var service = Ext.widget('SpecialUxLibFassadeClass',{
pin: '0815',
cfg: 'FileToLoadByAjax'
}).SpecialUxLibFactory.on('fileReadyEvent', function(){
console.log('service');
console.log(service.uncryptedConfig);


It notice the fired event - but I cannot touch the uncryptedConfig of cause.

I do not want to use SpecialUxLibFactory.on instead of on ... it is a Fassade-Class-Lib it should feel very easy.

I do not know how to go forward.

Maybe I need to know how to access Methods of the Service-Instance by the Mixin-Methods. Is there a key-word like "this" or "self" or "parent" ?

Please give me stuff to find my way :-)