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

Function createStore

packages/joint-react/src/data/create-store.ts:144–243  ·  view source on GitHub ↗
(options?: StoreOptions)

Source from the content-addressed store, hash-verified

142 * ```
143 */
144export function createStore(options?: StoreOptions): Store {
145 const { initialElements } = options || {};
146
147 const graph = createGraph(options);
148 // set elements to the graph
149 setElements({
150 graph,
151 initialElements,
152 });
153 // create store data - caching the elements and links for the react
154 const data = createStoreData();
155 const elementsEvents = subscribeHandler(forceUpdate);
156
157 const unsubscribe = listenToCellChange(graph, onCellChange);
158
159 data.updateStore(graph);
160 graph.on('batch:stop', onBatchStop);
161
162 const measuredNodes = new Set<dia.Cell.ID>();
163
164 /**
165 * Force update the graph.
166 * This function is called when the graph is updated.
167 * It checks if there are any unsized links and processes them.
168 * @returns changed ids
169 */
170 function forceUpdate(): Set<dia.Cell.ID> {
171 return data.updateStore(graph);
172 }
173 /**
174 * This function is called when a cell changes.
175 * It checks if the graph has an active batch and returns if it does.
176 * Otherwise, it notifies the subscribers of the elements events.
177 * @param cell - The cell that changed.
178 */
179 function onCellChange() {
180 if (graph.hasActiveBatch()) {
181 return;
182 }
183
184 elementsEvents.notifySubscribers();
185 }
186
187 /**
188 * This function is called when the batch stops.
189 */
190 function onBatchStop() {
191 elementsEvents.notifySubscribers();
192 }
193
194 /**
195 * Cleanup the store.
196 */
197 function destroy() {
198 unsubscribe();
199 graph.off('batch:stop', onBatchStop);
200 graph.clear();
201 data.destroy();

Callers 3

GraphProviderFunction · 0.90

Calls 6

setElementsFunction · 0.90
createStoreDataFunction · 0.90
subscribeHandlerFunction · 0.90
listenToCellChangeFunction · 0.90
forceUpdateFunction · 0.85
createGraphFunction · 0.70

Tested by

no test coverage detected