* Update the store data with the graph data. * @param graph - The graph to update the store data with.. * @description
(graph: dia.Graph)
| 33 | * @description |
| 34 | */ |
| 35 | function updateStore(graph: dia.Graph): Set<dia.Cell.ID> { |
| 36 | const cells = graph.get('cells'); |
| 37 | |
| 38 | if (!cells) throw new Error('Graph cells are not initialized'); |
| 39 | |
| 40 | // New updates, if cell is inserted or updated, we track it inside this diff. |
| 41 | const elementsDiff = new CellMap<Element>(); |
| 42 | const linkDiff = new CellMap<GraphLink>(); |
| 43 | const diffIds = new Set<dia.Cell.ID>(); |
| 44 | for (const cell of cells) { |
| 45 | if (cell.isElement()) { |
| 46 | const newElement = getElement<Element>(cell); |
| 47 | if (!util.isEqual(newElement, data.elements.get(cell.id))) { |
| 48 | elementsDiff.set(cell.id, newElement); |
| 49 | diffIds.add(cell.id); |
| 50 | } |
| 51 | } else if (cell.isLink()) { |
| 52 | const newLink = getLink(cell); |
| 53 | if (!util.isEqual(newLink, data.links.get(cell.id))) { |
| 54 | linkDiff.set(cell.id, newLink); |
| 55 | diffIds.add(cell.id); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | data.elements = diffUpdate(data.elements, elementsDiff, (cellId) => cells.has(cellId)); |
| 61 | data.links = diffUpdate(data.links, linkDiff, (cellId) => cells.has(cellId)); |
| 62 | return diffIds; |
| 63 | } |
| 64 | |
| 65 | const data: StoreData<Element> = { |
| 66 | updateStore, |
nothing calls this directly
no test coverage detected