(encoder, store, _sm)
| 113 | * @function |
| 114 | */ |
| 115 | export 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 |
no test coverage detected
searching dependent graphs…