Skip to content

Commit

Permalink
add native properties programtically rather than in the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Sep 2, 2016
1 parent 494061a commit b38b45e
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions src/js/tech/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,6 @@ import assign from 'object.assign';
import mergeOptions from '../utils/merge-options.js';
import toTitleCase from '../utils/to-title-case.js';

const NATIVE_GET = [
'paused',
'currentTime',
'buffered',
'volume',
'muted',
'poster',
'preload',
'autoplay',
'loop',
'error',
'seeking',
'seekable',
'ended',
'defaultMuted',
'playbackRate',
'played',
'networkState',
'readyState',
'videoWidth',
'videoHeight'
];
const NATIVE_SET = [
'volume',
'muted',
'src',
'poster',
'preload',
'autoplay',
'loop',
'playbackRate'
];

const NATIVE_FN = [
'pause',
'load'
];

/**
* HTML5 Media Controller - Wrapper for HTML5 Media API
*
Expand All @@ -68,22 +30,6 @@ class Html5 extends Tech {
constructor(options, ready) {
super(options, ready);

NATIVE_GET.forEach((prop) => {
this[prop] = () => this.el_[prop];
});

NATIVE_SET.forEach((prop) => {
const setterName = `set${toTitleCase(prop)}`;

this[setterName] = (v) => {
this.el_[prop] = v;
};
});

NATIVE_FN.forEach((prop) => {
this[prop] = () => this.el_[prop]();
});

const source = options.source;
let crossoriginTracks = false;

Expand Down Expand Up @@ -1096,6 +1042,60 @@ Html5.resetMediaElement = function(el) {
}
};

// Wrap native properties with a getter
[
'paused',
'currentTime',
'buffered',
'volume',
'muted',
'poster',
'preload',
'autoplay',
'loop',
'error',
'seeking',
'seekable',
'ended',
'defaultMuted',
'playbackRate',
'played',
'networkState',
'readyState',
'videoWidth',
'videoHeight'
].forEach(function(prop) {
Html5.prototype[prop] = function() {
return this.el_[prop];
};
});

// Wrap native properties with a setter
[
'volume',
'muted',
'src',
'poster',
'preload',
'autoplay',
'loop',
'playbackRate'
].forEach(function(prop) {
Html5.prototype[`set${toTitleCase(prop)}`] = function(v) {
this.el_[prop] = v;
};
});

// wrap native functions with a function
[
'pause',
'load'
].forEach(function(prop) {
Html5.prototype[prop] = function() {
return this.el_[prop]();
};
});

Component.registerComponent('Html5', Html5);
Tech.registerTech('Html5', Html5);
export default Html5;

0 comments on commit b38b45e

Please sign in to comment.