javascript - Client-Server AngularJS App - When should I update the model? -


i'm working on client-server application built angularjs. data exchanges i'm using html5 websockets. server has dataset exists copy on client. refer model here raw data.

via websockets i'm able get/set data. there may random data updates server (push).

i'm using different custom services/factories provide layer allows modules create data packets , send them server. provide wrapper model , may change reprasentation of data in view (like timestamps converted real time, etc.). have different controllers access services reach functions or values.

i hope describes current architecture enough. question:

on data updates server update model data , inform modules make use of data new value. it's like:

server -> model -> viewmodel -> view 

that works fine , guess it's ok view of mvvm pattern.

but i'm struggling bit publishing updates view. @ moment it's like:

view -> viewmodel -> model (at first update model)             |             -------> server (after send data server) 

so, when there's user updating data in view, viewmodel gets updated via angulars data binding. viewmodel calls service create output packet sent server. when packets gets commited model updated new data , packet given on websocket connection, updating data on server.

is the/one right way so? ok update model before packet sent server? should send update server, wait ok , update model?


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -