#cy.on(events, callback)
// Bind a direct listener
cy.on(events: string, callback: EventHandler<NodeData, EdgeData>): thisListen for core and bubbled element events: cy.on('tap', handler). For delegation, use cy.on('tap', ele => ele.isNode(), handler). Event names match literally; 'tap.ns' is different from 'tap'. Custom names are allowed and fire when your application emits them.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
callback: EventHandler<NodeData, EdgeData> | the event handler |
thisthis core, for chaining
Example
const seen = [];const handler = event => seen.push(event.type);cy.on('example', handler);cy.emit('example');cy.off('example', handler);console.log(seen); // ['example']#cy.on(events, predicate, callback)
// Bind a delegated listener
cy.on(events: string, predicate: ElePredicate<NodeData, EdgeData>, callback: EventHandler<NodeData, EdgeData>): thisListen for events on the core. Use cy.on('tap', handler) for core and bubbled element events. To delegate, use cy.on('tap', ele => ele.isNode(), handler).
Custom event names are accepted; a name the library never emits fires only when your application emits it. Event names match literally: 'tap.ns' is different from 'tap'. See the event reference for emitted names.
To remove a delegated listener, pass the same predicate and handler objects to off().
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
predicate: ElePredicate<NodeData, EdgeData> |
|
callback: EventHandler<NodeData, EdgeData> | the handler |
thisthis core, for chaining
Example
const seen = [];const handler = event => seen.push(event.target.id());cy.on('example', node => node.isNode(), handler);cy.getElementById('a').emit('example');console.log(seen); // ['a']Also spelled cy.addListener.
Core#off — remove listeners using the same function objects