@speechkit/speechkit-audio-player
Version:
A web player component that can play audio from https://speechkit.io
52 lines (41 loc) • 1.17 kB
JavaScript
export const noop = () => {}
export const bindPropWithElement = (map = {}, self, multi = false) => {
Object.keys(map).forEach(prop => {
const res = self.container.getElementsByClassName(map[prop])
self[prop] = multi ? res : res[0]
})
}
export const optimizedResize = (() => {
const callbacks = []
let running = false
const resize = () => {
if (!running) {
running = true
if (window.requestAnimationFrame) {
window.requestAnimationFrame(runCallbacks)
} else {
setTimeout(runCallbacks, 66)
}
}
}
const runCallbacks = () => {
callbacks.forEach(callback => callback())
running = false
}
const addCallback = callback => {
if (callback) callbacks.push(callback)
}
return {
add(callback) {
if (!callbacks.length) {
window.addEventListener('resize', resize)
}
addCallback(callback)
},
}
})()
export const fillWithPref = (obj, pref = 'js-') => Object.keys(obj).reduce((acc, next) => ({
...acc,
[next]: pref + obj[next],
}), {})
export const filterPodcasts = podcasts => podcasts.filter(podcast => podcast.media && podcast.media.length)