refactor: use es6 classes

Adds babel and uses es6 classes instead of class.extend
This commit is contained in:
Craig Weber 2022-07-19 12:23:30 -04:00
parent 9c44e09096
commit 03c63eae66
No known key found for this signature in database
13 changed files with 4554 additions and 550 deletions

View File

@ -1,5 +1,4 @@
{
"extends": "@silvermine/eslint-config/node"
"extends": "@silvermine/eslint-config/node",
"parser": "babel-eslint"
}

View File

@ -2,9 +2,6 @@
* Copyright (c) 2017 Jeremy Thomerson
* Licensed under the MIT license.
*/
'use strict';
var path = require('path'),
getCodeVersion = require('silvermine-serverless-utils/src/get-code-version');
@ -52,6 +49,26 @@ module.exports = function(grunt) {
main: {
src: config.js.standalone,
dest: config.dist.js.bundle,
options: {
transform: [
[
'babelify',
{
presets: [
[
'@babel/preset-env',
{
debug: true,
useBuiltIns: 'usage',
shippedProposals: true,
corejs: 3,
},
],
],
},
],
],
},
},
},

View File

@ -1,5 +1,3 @@
'use strict';
module.exports = {
extends: [ '@silvermine/standardization/commitlint.js' ],
};

5011
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -33,9 +33,17 @@
},
"homepage": "https://github.com/silvermine/videojs-quality-selector#readme",
"devDependencies": {
"@babel/core": "7.13.16",
"@babel/preset-env": "7.13.15",
"@commitlint/cli": "8.3.5",
"@commitlint/travis-cli": "8.3.5",
"@silvermine/eslint-config": "3.0.1",
"@silvermine/standardization": "2.0.0",
"autoprefixer": "8.6.5",
"babelify": "10.0.0",
"babel-eslint": "10.1.0",
"check-node-version": "4.0.3",
"core-js": "3.11.0",
"coveralls": "3.0.3",
"eslint": "6.8.0",
"expect.js": "0.3.1",
@ -62,7 +70,6 @@
"video.js": ">=6.0.0"
},
"dependencies": {
"class.extend": "0.9.1",
"underscore": "1.13.1"
}
}

View File

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'),
events = require('../events');

View File

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'),
events = require('../events'),
qualityOptionFactory = require('./QualityOption'),

View File

@ -1,9 +1,5 @@
'use strict';
module.exports = {
QUALITY_REQUESTED: 'qualityRequested',
QUALITY_SELECTED: 'qualitySelected',
PLAYER_SOURCES_CHANGED: 'playerSourcesChanged',
};

View File

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'),
events = require('./events'),
qualitySelectorFactory = require('./components/QualitySelector'),

View File

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'),
events = require('../events');

View File

@ -1,3 +1 @@
'use strict';
require('./index')();

View File

@ -1,17 +1,13 @@
'use strict';
var Class = require('class.extend');
module.exports = Class.extend({
init: function(player, seekToTime) {
class SafeSeek {
constructor(player, seekToTime) {
this._player = player;
this._seekToTime = seekToTime;
this._hasFinished = false;
this._keepThisInstanceWhenPlayerSourcesChange = false;
this._seekWhenSafe();
},
}
_seekWhenSafe: function() {
_seekWhenSafe() {
var HAVE_FUTURE_DATA = 3;
// `readyState` in Video.js is the same as the HTML5 Media element's `readyState`
@ -35,9 +31,9 @@ module.exports = Class.extend({
} else {
this._seek();
}
},
}
onPlayerSourcesChange: function() {
onPlayerSourcesChange() {
if (this._keepThisInstanceWhenPlayerSourcesChange) {
// By setting this to `false`, we know that if the player sources change again
// the change did not originate from a quality selection change, the new sources
@ -47,9 +43,9 @@ module.exports = Class.extend({
} else {
this.cancel();
}
},
}
onQualitySelectionChange: function() {
onQualitySelectionChange() {
// `onPlayerSourcesChange` will cancel this pending seek unless we tell it not to.
// We need to reuse this same pending seek instance because when the player is
// paused, the `preload` attribute is set to `none`, and the user selects one
@ -60,21 +56,23 @@ module.exports = Class.extend({
if (!this.hasFinished()) {
this._keepThisInstanceWhenPlayerSourcesChange = true;
}
},
}
_seek: function() {
_seek() {
this._player.currentTime(this._seekToTime);
this._keepThisInstanceWhenPlayerSourcesChange = false;
this._hasFinished = true;
},
}
hasFinished: function() {
hasFinished() {
return this._hasFinished;
},
}
cancel: function() {
cancel() {
this._player.off('canplay', this._seekFn);
this._keepThisInstanceWhenPlayerSourcesChange = false;
this._hasFinished = true;
},
});
}
}
module.exports = SafeSeek;

View File

@ -1,5 +1,3 @@
'use strict';
var expect = require('expect.js');
describe('Everything', function() {