MCPcopy Index your code
hub / github.com/Splidejs/splide / EventInterface

Function EventInterface

src/js/constructors/EventInterface/EventInterface.ts:34–79  ·  view source on GitHub ↗
( Splide?: Splide )

Source from the content-addressed store, hash-verified

32 * @return A collection of interface functions.
33 */
34export function EventInterface( Splide?: Splide ): EventInterfaceObject {
35 /**
36 * The document fragment for internal events.
37 * Provide the Splide instance to share the bus.
38 */
39 const bus = Splide ? Splide.event.bus : document.createDocumentFragment();
40
41 /**
42 * An event binder object.
43 */
44 const binder = EventBinder();
45
46 /**
47 * Listens to an internal event or events.
48 *
49 * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
50 * @param callback - A callback function to register.
51 */
52 function on( events: string | string[], callback: AnyFunction ): void {
53 binder.bind( bus, toArray( events ).join( ' ' ), e => {
54 callback.apply( callback, isArray( e.detail ) ? e.detail : [] );
55 } );
56 }
57
58 /**
59 * Triggers callback functions.
60 * This accepts additional arguments and passes them to callbacks.
61 *
62 * @param event - An event name.
63 */
64 function emit( event: string ): void {
65 // eslint-disable-next-line prefer-rest-params, prefer-spread
66 binder.dispatch( bus, event, slice( arguments, 1 ) );
67 }
68
69 if ( Splide ) {
70 Splide.event.on( EVENT_DESTROY, binder.destroy );
71 }
72
73 return assign( binder, {
74 bus,
75 on,
76 off: apply( binder.unbind, bus ),
77 emit,
78 } );
79}

Callers 15

mountFunction · 0.90
mountFunction · 0.90
LazyLoadFunction · 0.90
ArrowsFunction · 0.90
PaginationFunction · 0.90
MoveFunction · 0.90
CoverFunction · 0.90
LayoutFunction · 0.90
DragFunction · 0.90
AutoplayFunction · 0.90
ControllerFunction · 0.90
SlidesFunction · 0.90

Calls 4

EventBinderFunction · 0.90
assignFunction · 0.90
applyFunction · 0.90
onMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…