gautema / CQRSlite

A lightweight framework to help creating CQRS and Eventsourcing applications in C#
Other
1.1k stars 266 forks source link

How to handle the version property in react or angular frontend? #86

Closed LockTar closed 5 years ago

LockTar commented 5 years ago

Hi, we want some advice.

We are creating a new application that has a react frontend. In this frontend we have in example the details page of an entity. In example the entity customer. Let's say we can edit a field of a customer (in example phone number) so we have a popup that will let the user enter the new phone number. The phone number is pushed to the server with the latest version and command is executed.

But what then? Do we need to update the version on the client? Or are we refreshing the page? Or are we (re)loading the customer again so we get the latest version? How are you guys doing this?

Thanks

gautema commented 5 years ago

Hi. If you are doing everything synchronous, the easiest is probably to return the new customer from the save action or do a get on the customer directly after the save has finished. You could just return the version number as well (or just increment version by one), but if there are side effects from the save, you often have to implement the same logic several places which I find to be more trouble than it's worth.

If things are asynchronous things get a bit harder. Then the client need to subscribe to events from the server. This can be done using websockets, signalr or similar tech to get updates as they happen.

I have used both options myself and giving events can be a nice way to notify that something has changed on the server by an other user as well. But it's more work.

Hope this helps a bit.

LockTar commented 5 years ago

Thank you for the fast reply. We now implemented indeed the "refresh" option. So get the user again and update the field. Just like you would open the page. In this way you don't have to write client business logic for something that the server maybe already have done for you.

in example: Update lastname of customer => dto object from server will return firstname, lastname and fullname/displayname (first and lastname combined)

We were also thinking about websockets or signalr but in a later fase of the application. Now first other priorities.

gautema commented 5 years ago

Sounds good. I'm closing this as I hope you got answers to your questions. Just reach out again if theres any more questions.