This module is divided into two ends, client and server. These two segments cannot be confused.
npm install codos
Synchronization is mainly achieved by modifying attributes, such as Vue
let codosServer = new DServer();
let result = codosServer.setStore(store)
store = result;
codosServer.bindServer(server, "/data");
codosServer.start();
// initialization
let client = new SClient();
// Set the path of the binding
client.setPath("/data");
// Bind store
client.setStore(store.state);
// Return value
let result = client.getStore();
// Monitor data change
result.on("change", (target: any, key: string, value: any, ...data: any) => {
Vue.set(target, key, value);
})
client.start();
In this way, as long as the back-end data changes, it will be pushed to the front-end through websocket, which can cooperate with any framework to achieve the effect of dynamic updateIn the above example, as long as the 'result' of the server changes, for example:
result.ax = 12;
Such updates will be sent directly to the client