MCPcopy
hub / github.com/yjs/yjs / integrateStructs

Function integrateStructs

src/utils/encoding.js:189–324  ·  view source on GitHub ↗
(transaction, store, clientsStructRefs)

Source from the content-addressed store, hash-verified

187 * @function
188 */
189const integrateStructs = (transaction, store, clientsStructRefs) => {
190 /**
191 * @type {Array<Item | GC>}
192 */
193 const stack = []
194 // sort them so that we take the higher id first, in case of conflicts the lower id will probably not conflict with the id from the higher user.
195 let clientsStructRefsIds = array.from(clientsStructRefs.clients.keys()).sort((a, b) => a - b)
196 if (clientsStructRefsIds.length === 0) {
197 return null
198 }
199 const getNextStructTarget = () => {
200 if (clientsStructRefsIds.length === 0) {
201 return null
202 }
203 let nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.clients.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))
204 while (nextStructsTarget.refs.length === nextStructsTarget.i) {
205 clientsStructRefsIds.pop()
206 if (clientsStructRefsIds.length > 0) {
207 nextStructsTarget = /** @type {{i:number,refs:Array<GC|Item>}} */ (clientsStructRefs.clients.get(clientsStructRefsIds[clientsStructRefsIds.length - 1]))
208 } else {
209 return null
210 }
211 }
212 return nextStructsTarget
213 }
214 let curStructsTarget = getNextStructTarget()
215 if (curStructsTarget === null) {
216 return null
217 }
218
219 /**
220 * @type {StructStore}
221 */
222 const restStructs = new StructStore()
223 const missingSV = new Map()
224 /**
225 * @param {number} client
226 * @param {number} clock
227 */
228 const updateMissingSv = (client, clock) => {
229 const mclock = missingSV.get(client)
230 if (mclock == null || mclock > clock) {
231 missingSV.set(client, clock)
232 }
233 }
234 /**
235 * @type {GC|Item}
236 */
237 let stackHead = /** @type {any} */ (curStructsTarget).refs[/** @type {any} */ (curStructsTarget).i++]
238 // caching the state because it is used very often
239 const state = new Map()
240
241 // // caching the state because it is used very often
242 // const currentInsertSet = createIdSet()
243 // clientsStructRefsIds.forEach(clientId => {
244 // currentInsertSet.clients.set(clientid, new IdRanges(_createInsertSliceFromStructs(store.clients.get(clientId) ?? [], false)))
245 // })
246

Callers 1

readUpdateV2Function · 0.85

Calls 13

integrateMethod · 0.95
toUint8ArrayMethod · 0.95
getStateFunction · 0.90
createIDFunction · 0.90
getNextStructTargetFunction · 0.85
updateMissingSvFunction · 0.85
addStackToRestSSFunction · 0.85
writeClientsStructsFunction · 0.85
fromMethod · 0.80
pushMethod · 0.80
getMissingMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…