On the server
If the server is sending an object that implements Observable (or has a subscribe() method), then:
- Send the object as type
observable instead of plainObject
- Send the values of all public properties of the object. Also, the values of all public getters.
- (Make a
function isPrivateProperty(propertyName: string) which skips all properties starting with _, starting with #, and possibly others later.)
- Let the server subscribe to the object.
- Once the subscriber is called, send the updated property values to the client.
On the client
If the client receives an object of type observable,
- the client creates a stub (e.g.
RemoteObservable), similar to the plain object, but also sets all the properties that the server sent.
- The object implements
Observable with a subscribe() method and remembers the subscribers.
- If the server sends updated property values, the client updates the local object, and then calls the local subscribers.
Object lifetime
Pay attention for object lifetime.
- We don't want the client to hold on to objects which don't exist on the server anymore. (Hopefully, the collection observers will take care of that.) In other words, we should not have wild pointers.
- We don't want the server or client to keep objects alive which represent base objects that have been destroyed. In other words, we should not leak.
On the server
If the server is sending an object that implements
Observable(or has asubscribe()method), then:observableinstead ofplainObjectfunction isPrivateProperty(propertyName: string)which skips all properties starting with_, starting with#, and possibly others later.)On the client
If the client receives an object of type
observable,RemoteObservable), similar to the plain object, but also sets all the properties that the server sent.Observablewith asubscribe()method and remembers the subscribers.Object lifetime
Pay attention for object lifetime.