Expand description
interface SyncStrategy<I extends Item> {
keys: I["type"][];
awarenessUpdate(update: AwarenessUpdate, context: SyncContext): I[];
localEdit(yjsUpdate: Uint8Array, context: SyncContext): I[];
merge(items: I[]): I;
receive(item: I, context: SyncContext): I[];
sample(context: SyncContext): I[];
}Properties§
keys: I["type"][]The item types this strategy handles.
A combined strategy uses this to route incoming items to the strategy that owns their type.
Methods§
Source§awarenessUpdate(update: AwarenessUpdate, context: SyncContext): I[]
awarenessUpdate(update: AwarenessUpdate, context: SyncContext): I[]
Awareness state was updated.
This is the ephemeral application data being modified during editing.
Examples would be cursor moved, peer went online/offline (or a client re-announced that it is still online).
Return items to send that represent this update, or none if the strategy does not deal with awareness.
Source§localEdit(yjsUpdate: Uint8Array, context: SyncContext): I[]
localEdit(yjsUpdate: Uint8Array, context: SyncContext): I[]
A local edit was made to our document. Return items to send that represent this edit.
Source§receive(item: I, context: SyncContext): I[]
receive(item: I, context: SyncContext): I[]
An item came in from a peer.
Note that items can come in arbitrary order, so each item has to be handled independently.
It can be applied to context. It can also create items to
send in reply.
Source§sample(context: SyncContext): I[]
sample(context: SyncContext): I[]
We can create an item that samples our state.
This could mean the entire state is in the resulting item, or it could be an advert of our state in the form of a state vector.
What the sample is and how it is handled or responded to is up to the strategy. The sample is defined by when it is requested: once just before we send an outgoing message. The strategy may also decide it does not need to create a sample.
A sync strategy that handles a single item type: handle incoming items, determine what items to send.