MCPcopy
hub / github.com/shipshapecode/shepherd / on

Method on

shepherd.js/src/evented.ts:22–32  ·  view source on GitHub ↗

* Adds an event listener for the given event string. * * @param {string} event * @param {Function} handler * @param ctx * @param {boolean} once * @returns

(event: string, handler: AnyHandler, ctx?: unknown, once = false)

Source from the content-addressed store, hash-verified

20 * @returns
21 */
22 on(event: string, handler: AnyHandler, ctx?: unknown, once = false) {
23 if (isUndefined(this.bindings)) {
24 this.bindings = {};
25 }
26 if (isUndefined(this.bindings[event])) {
27 this.bindings[event] = [];
28 }
29 this.bindings[event]?.push({ handler, ctx, once });
30
31 return this;
32 }
33
34 /**
35 * Adds an event listener that only fires once for the given event string.

Callers 7

onceMethod · 0.95
step.spec.jsFile · 0.80
evented.spec.jsFile · 0.80
tour.spec.jsFile · 0.80
constructorMethod · 0.80
_setOptionsMethod · 0.80
bindAdvanceFunction · 0.80

Calls 1

isUndefinedFunction · 0.90

Tested by

no test coverage detected