Accessing viewComponent from mediator

Smith Wilson's Avatar

Smith Wilson

03 Jan, 2013 07:11 PM


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.

  1. Support Staff 1 Posted by Shaun Smith on 03 Jan, 2013 07:31 PM

    Shaun Smith's Avatar


    Injection is definitely the preferred approach. There isn't really a performance hit as the mediator is injected into regardless.

    The viewComponent accessor is actually write-only, and only exists for the sake of the helper methods (addViewListener and removeViewListener). 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:

    [Inject] public var view:ActualViewType;

    It's best to avoid _viewComponent as it is more of an implementation detail than anything else.

    Hope that helps!

  2. 2 Posted by Smith Wilson on 03 Jan, 2013 08:00 PM

    Smith Wilson's Avatar

    Thanks again Shaun!

  3. Support Staff 3 Posted by Shaun Smith on 03 Jan, 2013 08:05 PM

    Shaun Smith's Avatar

    Pleasure! Closing this for now, feel free to open new ones.

  4. Shaun Smith closed this discussion on 03 Jan, 2013 08:05 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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