MCPcopy
hub / github.com/clientIO/joint / updateStore

Function updateStore

packages/joint-react/src/data/create-store-data.ts:35–63  ·  view source on GitHub ↗

* Update the store data with the graph data. * @param graph - The graph to update the store data with.. * @description

(graph: dia.Graph)

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 7

getElementFunction · 0.90
getLinkFunction · 0.90
diffUpdateFunction · 0.90
addMethod · 0.80
getMethod · 0.45
setMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected