How to properly update Datas Model ?
Hi there,
I use rl2 and starling for a large evolutive project and I have some questions to work properly :
I use request/notification pattern to populate views via mediators.
My principal question is when view's user action is done where to update datas?
I think the right place is model. Am I right?
The other question is relative to the interface expose by the model :
For example if my vo class is like this :
ClassA_VO:
+propA:String;
+propB:ClassB_VO
ClassB_VO:
+propC:String;
+propD:Number;
If all properties are editable via user interfaces, I need to have all this methods in my model :
set currentClassAPropA
set currentClassAPropB (optional)
set currentClassAClassBPropC
set currentClassAClassBPropD
And need all the commands to fire this functions?
Thx in advance.
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
Support Staff 1 Posted by Ondina D.F. on 04 Jun, 2013 04:49 PM
Hi Harold,
Sorry for the late reply!!
You’re right, if the data is application’s data / application’s state. If you haven’t already, look at Model Responsibilities:
https://github.com/robotlegs/robotlegs-framework/wiki/best-practice...
If, on the other hand, you’re referring to data that’s only relevant for the View, like visual states, transitions, position etc, then you most probably won’t need to store that data into a model. But, of course, it depends on your use case. If you’d say what kind of data you’re trying to update, I’d give you a more specific answer.
I’m not sure I understand your question.
Are you talking about bindable VOs in your Views?
Usually, a VO (value object) is a data carrier class to shuttle typed data across tiers.
A Model deals with data, data modeler, responsible for holding and manipulating the application’s states
See Stray’s answers in this discussion:
http://knowledge.robotlegs.org/discussions/questions/352-stray-clar...
But, again, it depends on your use case whether you need to manipulate the VOs in a Model or directly in the View.
What will happen to all the propA, propB, propC, propD after they changed? Who needs them and when?
Ondina
2 Posted by harold.martin on 06 Jun, 2013 04:50 PM
Thx a lot for the answer, some words clarify the situation.
In my case datas are application's data.
Ok, the confusion came because i used to use Flex Framework and data binding...
Realy interesting but some thing goes unclarified for my case.
And :The application manage torque tools
I have this 2 VO's :
The ToolsModel has methods to set id, name and maxTorque and the torquesModel has methods to set value and unit.
There is also a view (called ToolInputView) containing an input torque component ( a textinput for the value and a picker list for the unit).
And the mediator for this component does'nt know anything about the tool (only the torque).
The question is how my ToolsModels can detects that's the property maxTorque was updated? (I know that's the model doesn't hear anything but a signal firing a command which call the public method on the data model to dispatch a tool updated signal)
Is it the responsibility of ToolInputMediator to dispatch a request update signal?
I'm not sure I'm very clear... Sorry for my poor english...
Support Staff 3 Posted by Ondina D.F. on 07 Jun, 2013 07:54 AM
Hey Harold,
Don’t worry; my English isn’t perfect either ;)
From what you’ve described I can’t know, if you really need 2 Models (ToolsModel and TorquesModel ) or if you could use just one Model to manipulate the 2 VOs.
If you need 2 Models:
ToolInputMediator re-dispatches an event (or signal) on behalf of ToolInputView. The payload would be the 2 VOs with the values set in the view.
The Command triggered by the event/signal accesses methods on TorquesModel to update TorquesVO with the values from the event’s payload:
torquesModel.value = payload.value;
e.t.c.
If TorquesModel would have a getter for TorquesVO, then you could access ToolsModel right away in the same command. Something like this:
toolsModel.maxTorque = torquesModel.getTorquesVO;
Then you can dispatch an event, if need be, to inform the mediator about the changes.
I hope this answers your question, but, if I misunderstood your use case, please let me know.
Ondina
Support Staff 4 Posted by Ondina D.F. on 07 Jun, 2013 10:19 AM
Reading your post again.
Who knows about the Tool? Or, rather, who needs the ToolModel after you modified it? Is it another Mediator? Are there a ToolsView and a TorquesView, each with its own mediator?
I don’t know what a Torque in your example is, but it seems you can’t have a Tool without a Torque, right? So, maybe before choosing a Tool, it’s mandatory to choose a Torque first in a TorqueView? Or, is it the other way around, you choose a Tool and then set the Torque’s values? Hehe, I’m confused, what comes first, the tool or the torque…?
Anyway, every time you’d change the Torque’s properties, you’d modify the ToolsModel as well, and let it or the command dispatch an event with the updated VO to the interested parties.
But, maybe the workflow is completely different from what I imagined, and you only need to let 2 Mediators communicate with each other, say TorqueMediator dispatches an event with TorqueVO (set in the TorqueView) as a payload, ToolsMediator is listening for it and passes the values to its view, and after having all the data for a Tool, including the maxTorque, it will send it to the Model (event->command->model)?
I don’t know. Maybe. More details about the real use case could be useful.
Support Staff 5 Posted by Ondina D.F. on 13 Jun, 2013 09:37 AM
I guess you’ve solved your issue. I’m closing this discussion for now, but feel free to re-open it, if need be.
Ondina D.F. closed this discussion on 13 Jun, 2013 09:37 AM.