( yContent: YMap<any>, events: YEvent<any>[], )
| 27 | const getYContent = (yContent: YMap<any>) => [yContent.get(T), yContent.get(V)]; |
| 28 | |
| 29 | const getChangesFromYDoc = ( |
| 30 | yContent: YMap<any>, |
| 31 | events: YEvent<any>[], |
| 32 | ): Changes => { |
| 33 | if (size(events) == 1 && arrayIsEmpty(events[0].path)) { |
| 34 | return [yContent.get(T).toJSON(), yContent.get(V).toJSON(), 1]; |
| 35 | } |
| 36 | const [yTables, yValues] = getYContent(yContent); |
| 37 | const tables = {} as any; |
| 38 | const values = {} as any; |
| 39 | arrayForEach(events, ({path, changes: {keys}}) => |
| 40 | arrayShift(path) == T |
| 41 | ? ifNotUndefined( |
| 42 | arrayShift(path) as string, |
| 43 | (yTableId) => { |
| 44 | const table = objEnsure(tables, yTableId, objNew) as any; |
| 45 | const yTable = yTables.get(yTableId) as YMap<YMap<Cell>>; |
| 46 | ifNotUndefined( |
| 47 | arrayShift(path) as string, |
| 48 | (yRowId) => { |
| 49 | const row = objEnsure(table, yRowId, objNew) as any; |
| 50 | const yRow = yTable.get(yRowId) as YMap<Cell>; |
| 51 | mapForEach( |
| 52 | keys, |
| 53 | (cellId, {action}) => |
| 54 | (row[cellId] = |
| 55 | action == DELETE ? undefined : yRow.get(cellId)), |
| 56 | ); |
| 57 | }, |
| 58 | () => |
| 59 | mapForEach( |
| 60 | keys, |
| 61 | (rowId, {action}) => |
| 62 | (table[rowId] = |
| 63 | action == DELETE |
| 64 | ? undefined |
| 65 | : yTable.get(rowId)?.toJSON()), |
| 66 | ), |
| 67 | ); |
| 68 | }, |
| 69 | () => |
| 70 | mapForEach( |
| 71 | keys, |
| 72 | (tableId, {action}) => |
| 73 | (tables[tableId] = |
| 74 | action == DELETE |
| 75 | ? undefined |
| 76 | : yTables.get(tableId)?.toJSON()), |
| 77 | ), |
| 78 | ) |
| 79 | : mapForEach( |
| 80 | keys, |
| 81 | (valueId, {action}) => |
| 82 | (values[valueId] = |
| 83 | action == DELETE ? undefined : yValues.get(valueId)), |
| 84 | ), |
| 85 | ); |
| 86 | return [tables, values, 1]; |
no test coverage detected
searching dependent graphs…