Idealism is what precedes experience; cynicism is what follows...

Friday, April 11, 2008

Adobe Flex : When to fetch Data

A frequent question among Flex developers is the question about when to fetch data.
During what phase in the component lifecycle should the model layer be called and asked for data, and if not present already, should the model layer access the data layer and fetch the data.
Let me start by pointing out that most developers do it wrong.
Most developers use the non-ambiguous creationComplete event or even worse, the applicationComplete. However certain the component is to all children being available and all settings being set, it inflicts a major overhead for the component as it after data has been fetched is typically forced to invalidate itself and hence do all initialization one more time... this time just with data.

The answer to the question about when to fetch data is in short the initialize event. You can use the preInitialize but outside the scope of this post, there can be certain issues when doing it at this time.

So, in conclusion... fetch the data at the initialize event and NOT at the creationComplete.

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Aluguel de Computadores, I hope you enjoy. The address is http://aluguel-de-computadores.blogspot.com. A hug.

My Network