Skip to content

cy.emit(events, extraParams?)

cy.emit — Core > Events. Cytoscape.js signatures, parameters and return contract.

cy.emit — Core › Events

Preview · Core › Events

Read in the complete API reference · All API members

// Emit an event on the core
cy.emit(events: string | EventProps, extraParams?: unknown[]): this

Emit an event on the core.

Custom event names are supported API, which is why on() validates none: cy.emit( 'myevent') runs handlers registered for 'myevent', and the same holds on elements. Names the library itself never emits are therefore legal to register and simply never fire — see on() for which those are.

Parameters
NameDescription
events: string | EventProps

one or more space-separated event names, or an event props object

extraParams: unknown[]?

extra arguments passed to each handler after the event object

Fields of events
NameDescription
type: string?
target: EventTarget?
cy: Core?
position: Position?

model-space position, for pointer-derived events

renderedPosition: Position?

rendered-space position; derived from position when omitted

originalEvent: NativeEvent?

the DOM event behind a gesture

layout: unknown?

the layout instance, on layoutstart/layoutready/layoutstop

cancelled: boolean?

on layoutstop: true when the run was abandoned by layout.cancel() or cy.destroy() rather than finished or stopped; on loadstop, when the load was cancelled

diff: PatchDiff?

on patch: what the patch added, removed and updated

progress: LoadProgress?

on loadstart/loadchunk/loadready/loadstop: how far the load has got

timeStamp: number?
Returns this

this core, for chaining

Example

let observed;
cy.one('example', event => { observed = event.type; });
cy.emit('example');
console.log(observed); // 'example'

Example graph and handle setup

Also spelled cy.trigger.