MCPcopy
hub / github.com/fabricjs/fabric.js / on

Method on

src/Observable.ts:28–52  ·  view source on GitHub ↗
(
    arg0: K | EventRegistryObject<EventSpec>,
    handler?: TEventCallback<E>
  )

Source from the content-addressed store, hash-verified

26 ): VoidFunction;
27 on(handlers: EventRegistryObject<EventSpec>): VoidFunction;
28 on<K extends keyof EventSpec, E extends EventSpec[K]>(
29 arg0: K | EventRegistryObject<EventSpec>,
30 handler?: TEventCallback<E>
31 ): VoidFunction {
32 if (!this.__eventListeners) {
33 this.__eventListeners = {} as Record<keyof EventSpec, TEventCallback[]>;
34 }
35 if (typeof arg0 === 'object') {
36 // one object with key/value pairs was passed
37 Object.entries(arg0).forEach(([eventName, handler]) => {
38 this.on(eventName as K, handler as TEventCallback);
39 });
40 return () => this.off(arg0);
41 } else if (handler) {
42 const eventName = arg0;
43 if (!this.__eventListeners[eventName]) {
44 this.__eventListeners[eventName] = [];
45 }
46 this.__eventListeners[eventName].push(handler);
47 return () => this.off(eventName, handler);
48 } else {
49 // noop
50 return () => false;
51 }
52 }
53
54 /**
55 * Observes specified event **once**

Callers 15

onceMethod · 0.95
initCenteringGuidelinesFunction · 0.80
initAligningGuidelinesFunction · 0.80
node_test_setup.jsFile · 0.80
parseRequestFunction · 0.80
startGoldensServerFunction · 0.80
canvas.jsFile · 0.80
assertCanvasDisposingFunction · 0.80
object.jsFile · 0.80
group.jsFile · 0.80

Calls 1

offMethod · 0.95

Tested by

no test coverage detected