PDA

View Full Version : Ext.regModel vs init and local variable



JFFortierQc
29 Nov 2011, 9:29 PM
Hi guys
I have 2 questions here. First, you need to know that I'm new to Sencha, but I'm on this Model for 3 days now (the model is more then the part of code pasted here). It's finished now and works great, but there is still questions in my mind that I need explanation.

Here is my code (part of it)

Ext.regModel('MediaModel', {
init: function() {
this.loadRemoteData();
},


fields: [
{name: 'thumbnailURL', type: 'string'},
{name: 'imgURL', type: 'string'},
{name: 'tempStore', type: 'auto'}
]
}


Questions 1 :
As you can see, I use the init:function, but in the API it does not exist. I'm sure you know the question. Why this works if that does not exist in the API? Or why it's not in the API because it is very useful when you need to know when the Model is ready? Without this init method, I would need to manually call the method after instantiation. So is that ok to use it? Does it can cause some problem? I need some info on that.

Question 2 :
In the fields, there is 2 real variables, and one named "tempStore" that I put there to be able to use it in the Model internally. So between methods and listeners inside the Model, I can refer to this temp variable like that this.tempStore = something;
Very useful and when I finished with it, I empty it to free up memory like that this.tempStore = null;
The question is : Is that ok? I mean, is there a better way to set internal model variable? Is there a better way to clear the variable? Here too, I need some information.

Thanks in advanced for your help on that

mitchellsimoens
30 Nov 2011, 11:22 AM
Not everything is in the API docs... either we didn't want it to or it never got the appropriate comments to get added.
You could just use the get method on the model to get the data... model.get('tempStore') and therefore you don't have to deal with the property and cleaning it up but great job cleaning it up!

JFFortierQc
30 Nov 2011, 7:01 PM
Hum ok
But about stuff that is not in the API, does the init is permit? Can it bugs if we use it to triggered a function at the Model initialization?

The problem is that I need to triggered something when the Model is ready. The init is just perfect for that or any listener. But it seams that there is no listener on it.

Thanks

mitchellsimoens
1 Dec 2011, 5:43 AM
Is the data present right away or does it have to load via a proxy?