| 60 | ); |
| 61 | |
| 62 | const yMapMatch = ( |
| 63 | yMapOrParent: YMap<any>, |
| 64 | idInParent: Id | undefined, |
| 65 | obj: {[id: Id]: any}, |
| 66 | set: (yMap: YMap<any>, id: Id, rawContent: any) => 1 | void, |
| 67 | ): 1 | void => { |
| 68 | const yMap = |
| 69 | idInParent == undefined |
| 70 | ? yMapOrParent |
| 71 | : (yMapOrParent.get(idInParent) ?? |
| 72 | yMapOrParent.set(idInParent, new YMap())); |
| 73 | let changed: 1 | undefined; |
| 74 | Object.entries(obj).forEach(([id, value]) => { |
| 75 | if (set(yMap, id, value)) { |
| 76 | changed = 1; |
| 77 | } |
| 78 | }); |
| 79 | yMap.forEach((_: any, id: Id) => { |
| 80 | if (obj[id] == null) { |
| 81 | yMap.delete(id); |
| 82 | changed = 1; |
| 83 | } |
| 84 | }); |
| 85 | if (idInParent != undefined && !yMap.size) { |
| 86 | yMapOrParent.delete(idInParent); |
| 87 | } |
| 88 | return changed; |
| 89 | }; |
| 90 | |
| 91 | const objEnsure = <Value>( |
| 92 | obj: {[id: Id]: Value}, |