UNPKG

@vime/core

Version:

Customizable, extensible, accessible and framework agnostic media player.

25 lines (21 loc) 805 B
'use strict'; const index = require('./index-86498cbd.js'); const withComponentRegistry = require('./withComponentRegistry-90ec334c.js'); const STATE_CHANGE_EVENT = 'vmStateChange'; /** * Creates a dispatcher on the given `ref`, to send updates to the closest ancestor player via * the custom `vmStateChange` event. * * @param ref An element to dispatch the state change events from. */ const createDispatcher = (ref) => (prop, value) => { const el = withComponentRegistry.isInstanceOf(ref, HTMLElement) ? ref : index.getElement(ref); const event = new CustomEvent(STATE_CHANGE_EVENT, { bubbles: true, composed: true, detail: { by: el, prop, value }, }); el.dispatchEvent(event); }; exports.STATE_CHANGE_EVENT = STATE_CHANGE_EVENT; exports.createDispatcher = createDispatcher;