Processing views automatically

Philip's Avatar

Philip

10 Oct, 2013 05:10 PM

Hi,

Thanks for a great framework!

How can I make the viewProcessorMap process a view automatically?
My current (working) solution is to mediate the view and manually process it in the mediator initializer.

The documentation states : "Assuming you're listening to your contextView, any view that lands on the contextView can be processed if it matches a mapping you've already created." I've made the mapping, but I am not sure what the first part of the sentence implies.

  1. Support Staff 1 Posted by Ondina D.F. on 11 Oct, 2013 08:35 AM

    Ondina D.F.'s Avatar

    Hi Philip,

    My current (working) solution is to mediate the view and manually process it in the mediator initializer.

    What do you mean by that? Setting some properties on the view?

    If so, then you could do this in your config:

    var someProperty:String = "someValue";
    injector.map(String).toValue(someProperty);
    viewProcessorMap.map(SimpleView).toInjection();
    

    then, in SimpleView:

    [Inject]
    public var someProperty:String;
    

    The moment SimpleView is added to the stage, it has access to someProperty, which has been set in the config.

    Assuming you're listening to your contextView, any view that lands on the contextView can be processed if it matches a mapping you've already created.

    Yeah, it is a misleading formulation:)
    You don't have to listen to your contextView explicitly. That's a robotlegs-context duty. The moment your context has been initialized, it is able to handle the views that are added and removed from stage through the ViewManager, as explained in the sentence above the one you cited:

    "In Robotlegs 2, stage-event listening is centralised to a ViewManager. The ViewManager listens for views landing on the stage, and being removed from stage, and informs interested parties, such as the viewProcessorMap, accordingly. "

    Did I answer your question?

    Ondina

  2. 2 Posted by Philip on 11 Oct, 2013 02:42 PM

    Philip's Avatar

    Hi Ondina,

    thank you for your answer.

    My current (working) solution is to mediate the view and manually process it in the mediator initializer.

    by this, I meant the following

     [Inject]
        public var view : SomeView;
        
        [Inject]
        public var viewProcessorMap : IViewProcessorMap;
    
        override public function initialize() : void
        {
            viewProcessorMap.process(view);
        }
    

    Your example is working out fine, thanks. I just can't seem to get it to work for Starling sprites. Not sure what goes on behind the scenes, but perhaps the issue lies with the StarlingViewMapExtension and how the Starling displayObjects are mapped.

  3. Support Staff 3 Posted by Ondina D.F. on 11 Oct, 2013 03:59 PM

    Ondina D.F.'s Avatar

    The ViewProcessorMap doesn't work with the Starling extensions I know of . They also have some issues with robotlegs' shared event dispatcher, because Starling has its own custom EventDispatcher ( for more details on this see:
    http://knowledge.robotlegs.org/discussions/problems/3815-injector-i...)

    If you tell me what exactly do you want to achieve, we could find alternative solutions together.

  4. 4 Posted by Philip on 12 Oct, 2013 08:26 AM

    Philip's Avatar

    Ah ok, I wasn't aware of that.
    Well, I am perfectly fine with the workaround listed above. Perhaps something along these lines:

    // AppConfig
    var someProperty:String = "someValue";
    injector.map(String).toValue(someProperty);
    viewProcessorMap.map(IProcessable).toInjection();
    mediatorMap.map(IProcessable).toMediator(ProcessableViewMediator);
    
    // ProcessableViewMediator
    [Inject]
    public var view : IProcessable;
    [Inject]
    public var viewProcessorMap : IViewProcessorMap;
    override public function initialize() : void { viewProcessorMap.process(view); }

    This would work for Starling views.

  5. Support Staff 5 Posted by Ondina D.F. on 12 Oct, 2013 10:29 AM

    Ondina D.F.'s Avatar

    Cool:) I'll mark this discussion as resolved. You can re-open it, if need be.

    Cheers,
    Ondina

  6. Ondina D.F. closed this discussion on 12 Oct, 2013 10:29 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