Skip to content

cy.startBatch()

cy.startBatch — Core > Graph manipulation > Batching and compaction. Cytoscape.js signatures, parameters and return contract.

cy.startBatch — Core › Graph manipulation › Batching and compaction

Preview · Core › Graph manipulation › Batching and compaction

Read in the complete API reference · All API members

// Open a batch: defer style application until the matching endBatch()
cy.startBatch(): this

Open a batch: defer style application until the matching endBatch(). Pairs nest — only the outermost endBatch() flushes. Prefer batch( fn), which cannot leak a depth on an exception.

The outermost open is a transaction and fires batchstart on the core — before any of the batch's mutations, with batching() already true, so a listener sees the state the transaction starts from (the place to take an undo snapshot) and anything it mutates belongs to the transaction. A nested open fires nothing.

Returns this

this core, for chaining

Example

cy.startBatch();
try { cy.getElementById('a').data('score', 5); }
finally { cy.endBatch(); }
console.log(cy.getElementById('a').data('score')); // 5

Example graph and handle setup