where to put a global variable

postite's Avatar

postite

11 Feb, 2013 08:46 AM

Hello All,

I'm starting to play with Robotlegs . I quite like the way it goes .
but 'm facing a question.
In my app, i have the need for a switch between edit and view mode.
so i have a boolean var like edit:Boolean wich is a toggled by a command .
everythings goes fine But . idon' t really know where to put this var .
is it stored in a model ? in my application view ? or in a ConfigVo ?

note that i am using a sort of port of Robotlegs in Haxe wich is NOT v2.
thanks

  1. Support Staff 1 Posted by Ondina D.F. on 11 Feb, 2013 02:34 PM

    Ondina D.F.'s Avatar

    Hello postite,

    It depends on the specific use case. Different use cases might require different solutions.
    It also depends on what you mean by “edit and view mode“.
    Are you talking about view states (visual states) or application states (state of the data), or both influencing each other?
    Usually, Models are responsible for handling application’s states and Views should handle their own states internally.

    If view’s state doesn’t affect application’s state, you don’t need to store this info anywhere. Events can carry this info in their payloads.
    If the view’s state is depending on the app’s state, you let its mediator react to events dispatched by a model, pass the payload to view’s API, and the view can decide in which state it hase to be.

    Here, a simple scenario with a UserDetailsView having 2 states “edit” and “view. Initial state “view”: input fields are not editable and a button is labeled as “load”. A click on “load” should load user details into that form, and change the state to “edit”. The Form is now editable and the button says “save”.
    What is your command supposed to do? Call a service to load data when a load button was clicked in the view, and save data when save button was clicked?

    I could expand on this use case, if you wanted me to, but it would be better and easier, if you presented details specific to your scenario:)

    Ondina

  2. 2 Posted by postite on 11 Feb, 2013 03:15 PM

    postite's Avatar

    thx for your interest Ondina.

    I have a layout( view/mediator) wich presents boxes (view components)
    i have another Editlayout (another view/mediator) wich is sitting on top (zindex) of my layout.
    pressing space keyboard key switch visibility of my EditLayout. I also activate a command that toggle a EDIT Boolean variable.

    i want my boxes component not to be draggable & resizable when EditLAyout is active.
    i want to shut view events ( MouseDownEvent, startDrag ...) when Edit is active.

    I just wonder where to put this EDIT var .
    i'd rather avoid coupling my mediators.
    but getting on top of my application just for a view switcher seems to be a bit overloading.
    actually i have got an EDIT static var sitting in my App (main class ) I guess it's not great.

    You partially answered my question by saying this.
    "If view’s state doesn’t affect application’s state, you don’t need to store this info anywhere. Events can carry this info in their payloads." if i understand, i have to fill my concerned views with my edit State stocked in my payload and not anywhere. my LAyout mediateor listen to the EDITSWITCHED signal and fill an editable BOOLEAN state in my view.
    is that right ?

    sory my rude english !

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

    Ondina D.F.'s Avatar

    Pseudo code:

    EditLayoutView:

    private function onViewVisibilityChanged()
    {
    //view dispatches an event, the payload is its visibility status
    dispatchEvent(new LayoutEvent(LayoutEvent.VISIBILITY_CHANGED, this.visible)
    }
    

    EditLayoutMediator:

    onregister()
    //here, add a listener for the view’s event, and redispatch it
    addViewListener(LayoutEvent.VISIBILITY_CHANGED, dispatch, LayoutEvent);
    

    LayoutMediator:

    onRegister()
    //listen for the event re-dispatched by the other mediator
    addContextListener(LayoutEvent.VISIBILITY_CHANGED, onLockView, LayoutEvent);
    private function onLockView(event: LayoutEvent):void
    {
    view. onLockView(event.visibility);
    }
    

    LayoutView

    private function onLockView(value:Boolean):void
    {
    this.disabled=value;
    //or you set a variable to this value, or do whatever you need to do here
    }
    
    LayoutEvent is a custom event with a property „visibility“ . Don’t forget to override clone().

    So, EditLayoutView and LayoutView communicate with each other through their mediators, which just listen to events dispatched by their views (and re dispatch them) or events dispatched by other mediators, or other actors.

    The logic would be similar when using signals.

    Does this help?

    sory my rude english !

    Hehe, don’t worry about your English, mine is not much better either

  4. 4 Posted by postite on 11 Feb, 2013 04:12 PM

    postite's Avatar

    thanks for your time and advices.
    You greatly answered my question.
    I sure will com back for another Q soon or later.
    thx again

  5. Support Staff 5 Posted by Ondina D.F. on 11 Feb, 2013 04:35 PM

    Ondina D.F.'s Avatar

    My pleasure :)
    Your questions will be welcomed!

  6. Ondina D.F. closed this discussion on 11 Feb, 2013 04:35 PM.

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