#cy.one(events, callback)
// Bind a direct listener
cy.one(events: string, callback: EventHandler<NodeData, EdgeData>): thisLike on(), but the handler runs at most once and then removes itself.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
callback: EventHandler<NodeData, EdgeData> | the handler, when delegating |
Returns
thisthis core, for chaining
Example
let count = 0;cy.one('example', () => count++);cy.emit('example');cy.emit('example');console.log(count); // 1#cy.one(events, predicate, callback)
// Bind a delegated listener
cy.one(events: string, predicate: ElePredicate<NodeData, EdgeData>, callback: EventHandler<NodeData, EdgeData>): thisLike on() with delegation, but the handler runs at most once.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
predicate: ElePredicate<NodeData, EdgeData> |
|
callback: EventHandler<NodeData, EdgeData> | the handler |
Returns
thisthis core, for chaining
Example
const seen = [];const handler = event => seen.push(event.target.id());cy.one('example', node => node.isNode(), handler);cy.getElementById('a').emit('example');console.log(seen); // ['a']Also spelled cy.once.