MCPcopy
hub / github.com/yjs/yjs / writeClientsStructs

Function writeClientsStructs

src/utils/encoding.js:115–138  ·  view source on GitHub ↗
(encoder, store, _sm)

Source from the content-addressed store, hash-verified

113 * @function
114 */
115export const writeClientsStructs = (encoder, store, _sm) => {
116 // we filter all valid _sm entries into sm
117 const sm = new Map()
118 _sm.forEach((clock, client) => {
119 // only write if new structs are available
120 if (getState(store, client) > clock) {
121 sm.set(client, clock)
122 }
123 })
124 getStateVector(store).forEach((_clock, client) => {
125 if (!_sm.has(client)) {
126 sm.set(client, 0)
127 }
128 })
129 // write # states that were updated
130 encoding.writeVarUint(encoder.restEncoder, sm.size)
131 // Write items with higher client ids first
132 // This heavily improves the conflict algorithm.
133 array.from(sm.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {
134 const structs = /** @type {Array<GC|Item>} */ (store.clients.get(client))
135 const lastStruct = structs[structs.length - 1]
136 writeStructs(encoder, structs, client, [new IdRange(clock, lastStruct.id.clock + lastStruct.length - clock)])
137 })
138}
139
140/**
141 * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder

Callers 2

integrateStructsFunction · 0.85
writeStateAsUpdateFunction · 0.85

Calls 7

getStateFunction · 0.90
getStateVectorFunction · 0.90
writeStructsFunction · 0.85
fromMethod · 0.80
forEachMethod · 0.45
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…