Multiple Instances of same view and mediator

kiran.may89's Avatar

kiran.may89

05 Jun, 2014 10:41 AM

Hi ,

I want to know is there a way of disabling the view and mediator of multiple instances of same in robot legs 1.5.2

  1. Support Staff 1 Posted by Ondina D.F. on 05 Jun, 2014 04:35 PM

    Ondina D.F.'s Avatar

    Could you please be more specific about what you mean by "disabling the view and mediator of multiple instances of same". What is your use case?

  2. 2 Posted by kiran.may89 on 11 Jun, 2014 12:25 PM

    kiran.may89's Avatar

    Thanks for the reply
    Here my scenario is Like this
    1.I have XVIewMediator,XView,XViewCommand
    2.I am opening this view using dispatch(new AppEvent(Appevent.OPEN_XVIEW));
    3. In that view i will click some object
    4. It will open the same view with other instance. means i am dispatch the same event for opening the view ie.dispatch(new AppEvent(Appevent.OPEN_XVIEW));
    5. So now i want disable all interactions , vew events and eventmap events of previous view before opening the new view
    I want to know is there any easy solution

  3. Support Staff 3 Posted by Ondina D.F. on 12 Jun, 2014 09:09 AM

    Ondina D.F.'s Avatar

    Hi,

    ** View to Mediator Events:

    When you add multiple instances of a view to the stage, each mediator is injected with an instance of the view it is mediating. SomeMediator (instance 1) will be injected with SomeView (instance 1), SomeMediator (instance 2) with SomeView (instance 2) and so on.
    Each mediator will react to an event dispatched by its own view. If the mediators have registered a listener for a view event, say SomeEvent.VIEW_NEEDS_DATA, and if SomeView (instance 1) dispatches this event, only SomeMediator ( instance 1) will react to the event.

    ** Application (other Mediators, Commands, Models..) to Mediator Events:

    If only one Mediator should react to an event, you can either check the state of the view or its ID, depending on the concrete use case. In your case, you probably would want to set/get a property on the view for its state, i.e. isActive (true, false), or isEnabled (true, false), or something more appropriate to your specific use case. When a Mediator is receiving an application event, it can check the state of the view in the event handler and decide if it should perform some action or not.

    If your use case is exactly as in your description, then it means that SomeView (instance 1) is controlling the opening and closing of SomeView (instance 2). So, when the user clicks on the mentioned button, you disable SomeView (instance 1) and its interactions from within the handler of the click event, and set the property isEnabled to false, then dispatch Appevent.OPEN_XVIEW and SomeMediator ( instance 1) will re-dispatch it. Now, when AppEvent.LIST_DATA_CHANGED (or another event) is dispatched by a model, SomeMediator (instance 1) will ignore this event, if isEnabled==false, while SomeMediator (instance 2) will pass the event's payload to SomeView (instance 2) to set the data provider of a list. When SomeView (instance 2) is removed from stage, SomeView (instance 1) isEnabled should be set to true. Of course, you can use isEnabled as a property of the mediator instead of the view, if you want. You will know what's better for your use case.

    Another possibility would be to remove the event listener for LIST_DATA_CHANGED (or any other context events) in SomeMediator (instance 1), either before re-dispatching OPEN_XVIEW, or after it has received the data provider for its view's list, in the handler of LIST_DATA_CHANGED. That, of course, would work only if the model's data is needed just once in the lifecycle of SomeView (instance 1), or if you had a way of adding the listener again when/if needed.

    For other scenarios you might want to store the views' ids or states in a model, but for what you described, I think using a filter based on the view's state would suffice.

    Does it solve your problem?

    Ondina

  4. 4 Posted by kiran.may89 on 12 Jun, 2014 09:23 AM

    kiran.may89's Avatar

    Hi Ondina D.F, Thank you for the response. The method explained is ok in this way i need to check the states or id's and views closing events. The process is sounds good but i need to take more care about errors and need to test in different scenarios.

    so finally in robotlegs there is no other way for disabling the mediator and it respective view.
    It would be very great if robotleg giving way of disabling the mediator and view

    Thank you

  5. Support Staff 5 Posted by Ondina D.F. on 12 Jun, 2014 10:07 AM

    Ondina D.F.'s Avatar

    You're welcome!

    In robotlegs version 2 (which I strongly recommend using) you can make use of the mediate/unmediate feature of the mediatorMap:

    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

  6. Support Staff 6 Posted by Ondina D.F. on 12 Jun, 2014 11:02 AM

    Ondina D.F.'s Avatar

    I forgot to say, that with robotlegs 1, when you map the view to a mediator you can set the autoCreate and autoRemove to false, and then create and remove your mediators manually:

    org.robotlegs.core.IMediatorMap.mapView(viewClassOrName:*, mediatorClass:Class, injectViewAs:*=null, autoCreate:Boolean=true, autoRemove:Boolean=true):void

    mediatorMap.createMediator(view);

    mediatorMap.removeMediator(mediator:IMediator)
    mediatorMap.removeMediatorByView(view)

    But I'm still recommending upgrading to robotlegs 2 :) It has many new or improved features.

  7. Ondina D.F. closed this discussion on 27 Jun, 2014 08:21 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