Connection with many views with their own instance of Model (via mediator)

Jenson's Avatar


27 Sep, 2013 08:25 AM

Hi there,
I have a consternation how to solve one problem:
In my app, I have one robotlegs singleton of model (let say ParentModel) which contains collection of other models (let say SubModel). It can add instance of SubModel which generates view instance of IView. SubModel contains other instances of its own for example FactoryClasses or Strategies.
Collection of SubModels I create in the beginning.

And my question is: how to connect particular SubModel with IView's mediator. It is possible to dispatch Signals from SubModel to particular Mediator without one "global mediator" which decides to which particular mediator should receive this Signal?

example of my idea:
var parentModel : ParentModel = new ParentModel();
parentModel.add(new SubModel(id1, new SomeFactory(), new SomeStrategy()));
parentModel.add(new SubModel(id2, new SomeFactory(), new SomeStrategy()));
parentModel.add(new SubModel(id3, new SomeFactory(), new SomeStrategy()));

please for quick answer :)
thanks in advance! :)

  1. Support Staff 1 Posted by Ondina D.F. on 27 Sep, 2013 12:55 PM

    Ondina D.F.'s Avatar

    Hi Jenson,

    I'm about to attend a weekend teleseminar.
    I'll notify my colleagues about your post, and I'm sure they'll respond as soon as their time permits:)


  2. Support Staff 2 Posted by Ondina D.F. on 29 Sep, 2013 08:40 AM

    Ondina D.F.'s Avatar

    I have a little break before my next seminar.
    Your setup isn't very clear to me, i.e. why are you generating view instances inside your model? Are the SubModels kind of a VO (value objects) or really Models? How are you changing models data and when? Are you injecting the ParentModel or SubModels somewhere?

    So, I'll use another scenario for my example, where the views are added to the stage from a parent view.

    Map a model like this:;

    This will return a newly created instance of the given type for each consecutive request.

    Create a new signal in the Mediator; add a handler for someSignal and then
    dispatch an Event or Signal to trigger a command with someSignal as the payload.

    private var someSignal:Signal ;
    override public function initialize():void
        someSignal = new Signal();
        dispatch(new SomeEvent(SomeEvent.SOME_TYPE, someSignal));

    After the View is added to the stage, the code inside Mediator's initialize() will run, and the command will be executed:

    public var someModel:ISomeModel;
    public var event:SomeEvent;
    public function execute():void
        someModel.someSignal = event.someSignal;

    SomeModel will generate an id every time it is created. Inside someModel.doSomething(), after some data changed: someSignal.dispatch(modelId);

    In Mediator's onModelChanged you receive a model id, which you can pass on to the view, for example. (Or, vice versa, when a View is added to the stage it generates a view id which will be sent to the command to be used by the model.)

    So, every added View will have its Mediator, which will trigger a Command where a new instance of ISomeModel will be created with its own Signal, and only the Mediator of that View will hear the Signal dispatched by that Model.

    As I said, I don't quite understand how your setup looks like, but maybe you can use a collection of signals mapped to model's id (created in your ParentModel??) and inject that collection into your mediators. Add a listener to the signal mapped to a specific id. I'm really not sure how this would work, though .

    The solution I gave you is based on Stray's idea of a request-response pattern.
    Search the forum for request-response +signal and look at Stray's answers, like these ones:

    Another possible solution would be to inject a signal as a singleton into models and mediators, and each mediator would then decide if it should respond to the signal based on views/models ids - assigned to them in your ParentModel (?)...

    That was my quick (though late) response;) More tomorrow, if need be. Let me know if that helped.


  3. 3 Posted by Jenson on 30 Sep, 2013 04:18 PM

    Jenson's Avatar

    thanks for reply.
    That is kind of what I was looking for :)
    the problem is that I have to start initialization from adding the view, but it depends from ParentModel: how many SubModels it contains...

    I'll check those links then...

  4. Support Staff 4 Posted by Ondina D.F. on 30 Sep, 2013 04:41 PM

    Ondina D.F.'s Avatar

    thanks for reply. That is kind of what I was looking for :)

    No problem:)

    the problem is that I have to start initialization from adding the view, but it depends from ParentModel: how many SubModels it contains...

    Yeah, but that's exactly what I didn't quite understand. If you need more help with this, please provide more info about the workflow of your app.
    And, in case you find a solution, let me know as well, so I can mark the discussion as resolved.


  5. Ondina D.F. closed this discussion on 11 Oct, 2013 09:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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