tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/819-need-to-know-about-using-viewmodelsRobotlegs: Discussion 2018-10-18T16:35:36Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/136561042012-02-13T18:03:19Z2012-02-13T18:03:45Zneed to know about using viewmodels<div><p>Hi,</p>
<p>Sorry if I understand wrong but I guess you have two option,<br>
1 You can either have a function in your model like getAPlusB()
which will return a+b and you can inject your model in your
mediator and then pass result to view or,<br>
2 You can have a command which will listen value changed event and
than calculate a+b and dispatch another event with result and
listen to this event from your mediator.</p>
<p>I hope this helps.<br>
Bulent</p></div>bulupetag:robotlegs.tenderapp.com,2009-10-18:Comment/136561042012-02-14T07:25:02Z2012-02-14T07:25:02Zneed to know about using viewmodels<div><p>thanks for the reply bulupe,</p>
<p>but what i get from robotlegs documentation , we must not inject
model into mediator.<br>
so i guess i cannot use point 1.</p>
<p>regarding point 2) i was thinking this can be done, however is
it right for a command to listen to events coming from model? i saw
the class flow diagram at<br>
<a href=
"http://www.robotlegs.org/diagram/">http://www.robotlegs.org/diagram/</a></p>
<p>and its clear that their is no communication from model ->
command , instead its always from command -> model, the diagram
suggests that a model can only dispatch events to the mediator of
the view. I have a doubt if your point 2) violates MVC
architechture.</p></div>itsmylifesohamtag:robotlegs.tenderapp.com,2009-10-18:Comment/136561042012-02-14T07:52:08Z2012-02-14T07:52:08Zneed to know about using viewmodels<div><p>Hi again,<br>
Ok a third way is your model can dispatch an event with a+b as
payload and mediator can listen to that event.</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/questions/309-inject-model-into-the-mediator">
http://knowledge.robotlegs.org/discussions/questions/309-inject-mod...</a>
Please read stray's comment.</p></div>bulupetag:robotlegs.tenderapp.com,2009-10-18:Comment/136561042012-02-14T08:34:44Z2012-02-14T08:34:44Zneed to know about using viewmodels<div><p>Hi bulupe,</p>
<p>i think this scheme again violates MVC, because now you model is
aware of what is being displayed in your view. tomorrow if i am
making another view for displaying a-b, then this scheme would
require me to dispatch another event from model with payload as
a-b. in MVC the model and view should be decoupled i think.</p>
<p>according to me the process of doing a+b should go as part of
the view logic. "let the view decide how it wants to display the
data in the model" . the model only says that it has changed.</p>
<p>the problem is when handling the "a or b changed event"
dispatched from model inside the view i need to manually access the
textbox.text property that displays the new a+b value. for eg. if
payload of the event are the values a,b then i have to do in the
viewlogic textbox.text = a+b; so i am losing the benefits of data
binding as i have to do it manually!<br>
in this case is it a good idea to have a viewmodel acting as a
layer between model and view? the viemodel is binded with the view.
when a "a or b changed event" comes from the model, we will just
alter the viewmodel rather than the view. since the viemodel is
binded with view , the view will reflect any change we do to the
viewmodel. is this a good scheme for robotlegs?</p></div>itsmylifesohamtag:robotlegs.tenderapp.com,2009-10-18:Comment/136561042012-02-14T09:15:57Z2012-02-14T09:15:57Zneed to know about using viewmodels<div><p>Hi again,</p>
<p>Sorry if I cause any misunderstanding, actually imaginary a and
b is hard to think of possibilities. But you can have an event for
a changed and another for b changed and your mediator can listen to
both events. And in your view you can have variables to hold a and
b so you can update them with events.<br>
And you can display both a+b or a-b in your view.<br>
Moreover as stray mentioned "When a view (or module) lands on stage
and it wants a particular type of data the onRegister of the
mediator sends a data request event. A command picks this up and
gets the data vo from the model and dispatches it on an event. The
mediator picks it up and we're away..."</p>
<p>I hope this helps, by the way I am not a Robotlegs guru :)</p></div>bulupe