Why I can inject a signal in Mediator and dispantch but not in view?

naghekyan's Avatar

naghekyan

11 Nov, 2013 10:06 PM

I have configured a signal like this:
 
       injector.map(XMLLoadedSignal).asSingleton();
       signalCommandMap.map( XMLLoadedSignal ).toCommand( XMLLoadedSignalCommand );

When I inject like this in Mediator of a view

    [Inject]
    public var xmlLoaded:XMLLoadedSignal;

and dispatch it, then the command is being executed, whereas if I do the same in the view, the xmlLoaded object is null. Why?

  1. Support Staff 1 Posted by Ondina D.F. on 12 Nov, 2013 09:56 AM

    Ondina D.F.'s Avatar

    More info about how injection works:

    See my answer here:
    http://knowledge.robotlegs.org/discussions/robotlegs-2/5766-automag...
    and these:
    https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...
    https://github.com/tschneidereit/SwiftSuspenders/blob/the-past/READ...

    So, you need a rule (a mapping), an injection point ([Inject]) and a way to let the Injector inspect the class that needs injection. If a view landing on the stage is not known by the framework, it won't be processed.
    One way of letting the injector know that a view needs to be inspected and processed is to use the ViewProcessorMap.
    There is a complex process going on behind the scenes, and I'm not going to go into details about it. All you need to know right now is that if you have the ViewManagerExtension, StageObserverExtension, ViewProcessorMapExtension and StageCrawlerExtension installed ( all of them provided by the MVCSBundle by default), they will take care of views landing on the stage, and if the injector finds a rule like this one :

    injector.map(SomeObject).asSingleton();
    

    and the ViewProcessorViewHandler has added SomeView to its list of interestedMappings, because you did this:

    viewProcessorMap.map(SomeView).toInjection();
    

    SomeView will be processed and inspected,

    and if the Injector finds an injection point:

    [Inject]
    public var someObject:SomeObject;
    

    it will provide the dependency (SomeObject) to the view (SomeView), the moment SomeView is added to the stage.

    My explanation is really bad:) Hopefully, though, you'll get the point.
    So if you want to inject a signal into a view by using the viewProcessorMap, you need a mapping for the signal, as you've already done, and this:

    viewProcessorMap.map(SomeView).toInjection();

    where SomeView is your view that needs the signal.

  2. 2 Posted by naghekyan on 12 Nov, 2013 10:34 AM

    naghekyan's Avatar

    Let me not agree with you. Your explanation is really good! :) Thank you very much! :)

  3. Support Staff 3 Posted by Ondina D.F. on 12 Nov, 2013 11:09 AM

    Ondina D.F.'s Avatar

    Hehe, thank you. Glad it helped.

  4. Ondina D.F. closed this discussion on 12 Nov, 2013 11:09 AM.

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