Access Question

Timur's Avatar

Timur

24 Sep, 2012 12:53 PM

Hi there. Simple question:
I have a main View and it's Mediator. This Mediator instantiates other (child) Views, in a runtime, each with it's own Model and Mediator. The position of each new child (which I set in the main Mediator) depends on the properties stored inside models of previously created children. So the question is, what is the best approach to access these models?
Thank You!

  1. Support Staff 1 Posted by Ondina D.F. on 24 Sep, 2012 03:16 PM

    Ondina D.F.'s Avatar

    Hello Timur,

    A common flow looks like this:

    Map a custom event to a Command.
    Dispatch a custom event from your View, when you need data from the Model. The Mediator listens for that event and re-dispatches the custom event to trigger the Command.
    The Command accesses the Model’s API, say getOldViewPosition().
    The Model dispatches a custom event with the (calculated or stored) positions as a payload (better in form of a VO-value object).
    The Mediator listens for the event dispatched by the Model and passes the payload to its View, which then creates the new children with the received positions.

    Maybe you need to pass data from the View to the Model too. You can send a Rectangle object ( x, y, width, height) as the payload of the event dispatched by the View, re-dispatched by the Mediator to trigger the command. The Model can use it for calculations.

    It depends on your use case how you transport the data (VO, Rectangle, Array/Vector of x, y positions..) between Models and Mediators.

    The position of each new child (which I set in the main Mediator) depends on the properties stored inside models of previously created children.

    This logic belongs to the View itself. When the Mediator catches the event dispatched by the Model, it passes the properties of the previous child to the View. The View will add or remove children, resize, reposition them, and so on.

    If a View needs data, it asks its Mediator to relay the request to the rest of the application (Models, Services, other Mediators..).
    If Models or Services have data for a View, the Mediator catches their events and provides its View with the payload.

    I think that almost 90% of the discussions on this forum were about Models and how to use them. If you feel like it, you can read through the discussions to get an idea about the different ways of using (or misusing) Models.
    You’ll have to decide for yourself which approach makes the most sense for your specific use case :)

    Ondina

  2. 2 Posted by Timur on 24 Sep, 2012 03:54 PM

    Timur's Avatar

    Oh! So my problem is actually in overloading the Mediator class, which actually meant to be a simple doorway.
    Thank you Ondina!

  3. Support Staff 3 Posted by Ondina D.F. on 25 Sep, 2012 10:39 AM

    Ondina D.F.'s Avatar

    You're welcome, Timur.

    Oh! So my problem is actually in overloading the Mediator class, which actually meant to be a simple doorway.

    Exactly.

  4. Ondina D.F. closed this discussion on 25 Sep, 2012 10:39 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