( Splide?: Splide )
| 32 | * @return A collection of interface functions. |
| 33 | */ |
| 34 | export 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 | } |
no test coverage detected
searching dependent graphs…