#cy.off(events, callback?)
// Remove a direct listener
cy.off(events: string, callback?: EventHandler<NodeData, EdgeData>): thisStop listening. Removing a delegated handler takes the same ( events, predicate, handler) triple it was added with — predicates compare by function identity, so the predicate must be the same function object, not an equivalent one.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
callback: EventHandler<NodeData, EdgeData>? | the handler, when delegating |
thisthis core, for chaining
Example
let count = 0;const handler = () => count++;cy.on('example', handler);cy.off('example', handler);cy.emit('example');console.log(count); // 0#cy.off(events, predicate, callback)
// Remove a delegated listener
cy.off(events: string, predicate: ElePredicate<NodeData, EdgeData>, callback: EventHandler<NodeData, EdgeData>): thisRemove a delegated handler. The predicate must be the same function object it was registered with — predicates compare by identity, not by structure.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
predicate: ElePredicate<NodeData, EdgeData> | the predicate the handler was added with |
callback: EventHandler<NodeData, EdgeData> | the handler to remove |
thisthis core, for chaining
Example
const seen = [];const handler = event => seen.push(event.target.id());cy.on('example', node => node.isNode(), handler);const predicate = node => node.isNode();cy.on('removed', predicate, handler);cy.off('removed', predicate, handler);cy.getElementById('a').emit('removed');console.log(seen); // []Also spelled cy.removeListener.