Skip to content

cy.batch(fn)

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

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

Preview · Core › Graph manipulation › Batching and compaction

Read in the complete API reference · All API members

// Run fn inside a startBatch()/endBatch() pair
cy.batch(fn: () => void): this

Run fn inside a startBatch()/endBatch() pair. The batch closes even if fn throws, so this is the form to prefer. As the outermost pair it is one transaction, batchstart … batchend; there is no rollback, so a throwing fn still ends in batchend, with the mutations that landed before the throw.

Parameters
NameDescription
fn: () => void

the mutations to batch; its return value is discarded

Returns this

this core, for chaining

Example

cy.batch(() => { cy.nodes().unselect(); cy.getElementById('a').select(); });
console.log(cy.getElementById('a').selected()); // true

Example graph and handle setup