After an update call to a server, should you load all items again?
I'm having a not so much robotlegs related question, but more overall architecture, and I was hoping someone could help.
I'm currently working on a client application (AIR, flex,
robotlegs, signals).
On startup the application loads about 500 items from a server.
This takes up to 4 seconds (it is a lot of data over SOAP).
But after editing the items in the application, i do a updateJob(
job : JobVo ) call to the server.
I'm used to update my items and on responce to do a
getAllItems().
This is how I usually work, because I think it is clean to have the
vo's generated based on the data on the server, to make sure I'm
never working with objects that are different in my client than on
the server.
But since the call takes up to 4 seconds, this might be a not so
clean sollution..
I'm wondering how people here usually deal with this, and if you think it is ok to just push the updated object into the model, while also passing it to the server..
Hope my explanation makes sense, and you understand what I mean...
Hans
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 16 Feb, 2012 04:37 PM
Hi Hans,
My take on this:
It sounds like your VOs are a 1:1 representation of a record in a db table. In this case your Model class would be the representation of that table, holding a collection of all VOs.
When you load data from the server on start-up, you create those VOs and add them to the collection.
When you edit one or more items in the View, you update the Model, i.e. the corresponding VOs and collection, and you want to update the db table.
a. In case of a simple update:
If you send only the updated VOs to the server, the server-side code takes care of updating the corresponding records in your db table, and if the returned message isn’t an error, you can be sure that your client and server data are in sync. No need to getAllItems again.
b. In case that editing an item in the View would require some additional data from the server:
If, for example, you had a User table on the server and a UserModel on the client, and when you edited a User’s role in your client’s View, you wanted to get a set of pictures or other info ,corresponding to that role, from another db table, the server would update the User table with the new roles and send back only the set of additional data for the updated user(s). On the client you’d update the Models accordingly and the View would show the changes. Not the best example, but I hope you get it.
So, if I understood your use case correctly, the steps would be:
Client to server:
-View edits items
-Model updates VOs and VOs collection
-Service sends a collection of updated VOs to server
Server to client:
-server updates tables
a. server sends a success message to client
or
b.
-sends data from other tables for the updated records
-Model updates VOs
-View shows additional info for the updated item(s)
In this scenario, Models and VOs are closely coupled with the db structure.
A change in one necessitates a change in the other, but you don’t need to update the Model, then update the db and then reload all items and update the Model again, in my opinion.
Hope that makes sense:)
Ondina
2 Posted by dotdotcommadot on 17 Feb, 2012 11:26 AM
Hi Ondina,
This makes very much sense :).
Thanx for your reply!!
I think i was probably being too pragmatic about needing to map the vo's to the the server.. It always felt a bit weird to put data in the models, when it doesn't come from the server.
But I think you're right, this way should be fail safe as well as long as I can rely on the response from the server.
Thx a lot!
H.
Support Staff 3 Posted by Ondina D.F. on 17 Feb, 2012 12:36 PM
You’re welcome, Hans:)
Yes, I know it’s a bit confusing, because of the different interpretations of the term ‘Model’, but Models in rl can fulfill different purposes, depending on what you need:
“In addition to controlling access to data, models maintain the state of your application.“
[from http://joelhooks.com/2011/03/12/an-introduction-to-robotlegs-as3-pa...]
"A model class is used to manage access to an application’s data model. A model provides an API that is used by other framework actors to access, manipulate, and update application data. This data includes, but is not limited to, native data types such as String, Array, or ArrayCollection as well as domain specific Objects or collections of these. " [from https://github.com/robotlegs/robotlegs-framework/wiki/best-practice...]
I’m going to close this discussion, but if you have more questions, you can re-open it, or start a new discussion.
Cheers,
Ondina
Ondina D.F. closed this discussion on 17 Feb, 2012 12:36 PM.