@hippy4tv/waterfall
Version:
Hippy for TV!
55 lines (48 loc) • 1.19 kB
JavaScript
/**
* Capitalize a word
*
* @param {string} s The word input
* @returns string
*/
function capitalize(str) {
if (typeof str !== 'string') {
return '';
}
return `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
}
/**
* Get binding events redirector
*
* The function should be calld with `getEventRedirector.call(this, [])`
* for binding this.
*
* @param {string[] | string[][]} events events will be redirect
* @returns Object
*/
function getEventRedirector(events) {
const on = {};
events.forEach((event) => {
if (Array.isArray(event)) {
const [exposedEventName, nativeEventName] = event;
if (Object.prototype.hasOwnProperty.call(this.$listeners, exposedEventName)) {
on[event] = this[`on${capitalize(nativeEventName)}`];
}
} else if (Object.prototype.hasOwnProperty.call(this.$listeners, event)) {
on[event] = this[`on${capitalize(event)}`];
}
});
return on;
}
function registerWaterfall(Vue) {
Vue.registerElement('my-waterfall', {
component: {
name: 'Waterfall',
},
});
Vue.component('waterfall', {
props: {
color: Number,
},
});
}
export default registerWaterfall;