tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/6573-connection-with-many-views-with-their-own-instance-of-model-vie-mediatorRobotlegs: Discussion 2013-10-11T09:17:56Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/290502342013-09-27T12:55:27Z2013-09-27T12:55:27ZConnection with many views with their own instance of Model (via mediator)<div><p>Hi Jenson,</p>
<p>I'm about to attend a weekend teleseminar.<br>
I'll notify my colleagues about your post, and I'm sure they'll
respond as soon as their time permits:)</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/290502342013-09-29T08:40:53Z2013-09-29T08:44:41ZConnection with many views with their own instance of Model (via mediator)<div><p>I have a little break before my next seminar.<br>
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?</p>
<p>So, I'll use another scenario for my example, where the views
are added to the stage from a parent view.</p>
<p>Map a model like this:</p>
<pre>
<code>injector.map(ISomeModel).toType(SomeModel);</code>
</pre>
<p>This will return a newly created instance of the given type for
each consecutive request.</p>
<p>Create a new signal in the Mediator; add a handler for
someSignal and then<br>
dispatch an Event or Signal to trigger a command with someSignal as
the payload.</p>
<pre>
<code>private var someSignal:Signal ;
override public function initialize():void
{
someSignal = new Signal();
someSignal.add(onModelChanged);
dispatch(new SomeEvent(SomeEvent.SOME_TYPE, someSignal));
}</code>
</pre>
<p>After the View is added to the stage, the code inside Mediator's
initialize() will run, and the command will be executed:</p>
<pre>
<code>[Inject]
public var someModel:ISomeModel;
[Inject]
public var event:SomeEvent;
public function execute():void
{
someModel.someSignal = event.someSignal;
someModel.doSomething();
}</code>
</pre>
<p>SomeModel will generate an id every time it is created. Inside
someModel.doSomething(), after some data changed:
someSignal.dispatch(modelId);</p>
<p>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.)</p>
<p>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.</p>
<p>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 .</p>
<p>The solution I gave you is based on Stray's idea of a
request-response pattern.<br>
Search the forum for request-response +signal and look at Stray's
answers, like these ones:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/213-no-subject#comment_3760752">
http://knowledge.robotlegs.org/discussions/problems/213-no-subject#...</a><br>
<a href=
"http://knowledge.robotlegs.org/discussions/problems/322-request-model-form-mediator-mechanism">
http://knowledge.robotlegs.org/discussions/problems/322-request-mod...</a></p>
<p>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 (?)...</p>
<p>That was my quick (though late) response;) More tomorrow, if
need be. Let me know if that helped.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/290502342013-09-30T16:18:53Z2013-09-30T16:18:53ZConnection with many views with their own instance of Model (via mediator)<div><p>thanks for reply.<br>
That is kind of what I was looking for :)<br>
but:<br>
the problem is that I have to start initialization from adding the
view, but it depends from ParentModel: how many SubModels it
contains...</p>
<p>I'll check those links then...<br>
cheers:)</p></div>Jensontag:robotlegs.tenderapp.com,2009-10-18:Comment/290502342013-09-30T16:41:08Z2013-09-30T16:41:08ZConnection with many views with their own instance of Model (via mediator)<div><blockquote>
<p>thanks for reply. That is kind of what I was looking for :)</p>
</blockquote>
<p>No problem:)</p>
<blockquote>
<p>the problem is that I have to start initialization from adding
the view, but it depends from ParentModel: how many SubModels it
contains...</p>
</blockquote>
<p>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.<br>
And, in case you find a solution, let me know as well, so I can
mark the discussion as resolved.</p>
<p>Ondina</p></div>Ondina D.F.