PhysicalReplica
Replica is a primitive for data replication. The replica's task is to represent some chunk of data from a server on a client side. Replica is configured by Fetcher and ReplicaSettings. Replica loads missing data when an active observer connects (see: Replica.observe). Replica keeps track of data staleness. Replica refreshes stale data when an active observer is connected. Replica deduplicates network requests (it doesn't coll a new request if another one is in progress). Replica cancels network request when a last observer is disconnected. Replica clears data when it has no observers for a long time.
The difference between Replica and PhysicalReplica is that the latter has a richer API. Replica has minimalistic read-only API, whereas PhysicalReplica allows to cancel requests, modify data, execute optimistic updates. PhysicalReplica extends Replica, but not all replicas are physical replicas. There are lightweight virtual replicas created by combining other replicas (see: replica-algebra module for more details).
Functions
Begins optimistic update. Observed data will be transformed by update function immediately.
Clears error stored in ReplicaState.
Commits optimistic update. Replica forgets previous data.
Makes data stale if it is exists. It also could call a refresh depending on InvalidationMode.
Modifies current data with transform function if it is exists.
Starts to observe a replica. Returned ReplicaObserver gives access to replica state and error events.
Loads fresh data from a network if it is stale.
Rollbacks optimistic update. Observed data will be replaced to the previous one.
Properties
Notifies that some ReplicaEvent has occurred.
Provides ReplicaState as an observable value.
Extensions
Returns current ReplicaState.