R
R
rakro2016-01-14 17:05:05
Angular
rakro, 2016-01-14 17:05:05

Model of interaction with the server?

There is a certain essence - for example "Task". There is a function on the backend (let's call it get_json) that returns json (a rather complicated structure) from which this entity will be rendered by angular. Many different actions can be performed on this entity, during which the entity can change greatly, and consequently its display. The idea is to do this - for each action on the entity (ng-click), a request will be made to the http api (via the $http service). Certain operations will take place on the backend. In the response, one of the fields will be the result of the get_json function, which will return json for the already changed entity. Next, I simply replace the entire object in $scope, which is now rendered, with the new one that came in the response. Is this a normal model of interaction with the server or is it an addiction?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2016-01-15
Protko @Fesor

Read about Event Sourcing and Redux. These approaches mean exactly what you want. And yes, all this is great friends with angular.
In short, we generate an action using ngClick, send it to the server and apply the action to the structure on the client (optimistic update). Well, etc. periodically synchronizing the whole thing.
ps do not use $scope, never (more precisely, think 10 times if you can do without it).

R
Rodion Shergin, 2016-01-14
@beh

As I understand it, you need to save the state of the client application on the server, with any user actions, so that later this state can be restored, for example, when the page is refreshed?
It seems to me that it is better to make changes to the entity on the client, and periodically dump it on the server. Such updates can be done via _.debounce , i.e. accumulate changes in the state for a certain time and then save it on the server. If the user will randomly poke at everything, then every time to pull the server is not optimal, it is better to pull once when he calms down.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question