Accessing viewComponent from mediator
Hi,
I notice in RL2 the Mediator's
viewComponent property is read-only. In all the
examples that I can find, I see the view being injected and
accessed that way. Just curious as to why this is the case. In RL1
I would usually create a helper that returned the viewComponent
correctly typed:
pubic function get myCustomView():MyCustomView
{
return viewComponent as MyCustomView;
}
I definitely see that injecting results in less code:
[Inject] public var viewComponent:MyCustomView;
Is there a performance hit for injection vs the helper method?
Just want to gain some intuitive understanding of what's going on.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
Support Staff 1 Posted by Shaun Smith on 03 Jan, 2013 07:31 PM
Hi,
Injection is definitely the preferred approach. There isn't really a performance hit as the mediator is injected into regardless.
The
viewComponentaccessor is actually write-only, and only exists for the sake of the helper methods (addViewListenerandremoveViewListener). It's write-only as an attempt to discourage use of the property, and encourage injecting the correct type rather than casting. The preferred style is:It's best to avoid
_viewComponentas it is more of an implementation detail than anything else.Hope that helps!
2 Posted by Smith Wilson on 03 Jan, 2013 08:00 PM
Thanks again Shaun!
Support Staff 3 Posted by Shaun Smith on 03 Jan, 2013 08:05 PM
Pleasure! Closing this for now, feel free to open new ones.
Shaun Smith closed this discussion on 03 Jan, 2013 08:05 PM.