Skip to content

Commit cc84ff4

Browse files
committed
refactor: remove internal Map, Set, and WeakMap shams, assume window.performance and requestAnimationFrame support (#7775)
1 parent 28029d9 commit cc84ff4

File tree

11 files changed

+55
-342
lines changed

11 files changed

+55
-342
lines changed

src/js/component.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import * as Fn from './utils/fn.js';
1111
import * as Guid from './utils/guid.js';
1212
import {toTitleCase, toLowerCase} from './utils/str.js';
1313
import {merge} from './utils/obj.js';
14-
import Map from './utils/map.js';
15-
import Set from './utils/set.js';
1614
import keycode from 'keycode';
1715

1816
/**
@@ -1508,11 +1506,6 @@ class Component {
15081506
* @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame}
15091507
*/
15101508
requestAnimationFrame(fn) {
1511-
// Fall back to using a timer.
1512-
if (!this.supportsRaf_) {
1513-
return this.setTimeout(fn, 1000 / 60);
1514-
}
1515-
15161509
this.clearTimersOnDispose_();
15171510

15181511
// declare as variables so they are properly available in rAF function
@@ -1595,11 +1588,6 @@ class Component {
15951588
* @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame}
15961589
*/
15971590
cancelAnimationFrame(id) {
1598-
// Fall back to using a timer.
1599-
if (!this.supportsRaf_) {
1600-
return this.clearTimeout(id);
1601-
}
1602-
16031591
if (this.rafIds_.has(id)) {
16041592
this.rafIds_.delete(id);
16051593
window.cancelAnimationFrame(id);
@@ -1732,17 +1720,6 @@ class Component {
17321720
}
17331721
}
17341722

1735-
/**
1736-
* Whether or not this component supports `requestAnimationFrame`.
1737-
*
1738-
* This is exposed primarily for testing purposes.
1739-
*
1740-
* @private
1741-
* @type {Boolean}
1742-
*/
1743-
Component.prototype.supportsRaf_ = typeof window.requestAnimationFrame === 'function' &&
1744-
typeof window.cancelAnimationFrame === 'function';
1745-
17461723
Component.registerComponent('Component', Component);
17471724

17481725
export default Component;

src/js/player.js

Lines changed: 26 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,46 +4313,28 @@ class Player extends Component {
43134313

43144314
this.audioOnlyMode_ = value;
43154315

4316-
const PromiseClass = this.options_.Promise || window.Promise;
4317-
4318-
if (PromiseClass) {
4319-
// Enable Audio Only Mode
4320-
if (value) {
4321-
const exitPromises = [];
4322-
4323-
// Fullscreen and PiP are not supported in audioOnlyMode, so exit if we need to.
4324-
if (this.isInPictureInPicture()) {
4325-
exitPromises.push(this.exitPictureInPicture());
4326-
}
4327-
4328-
if (this.isFullscreen()) {
4329-
exitPromises.push(this.exitFullscreen());
4330-
}
4331-
4332-
if (this.audioPosterMode()) {
4333-
exitPromises.push(this.audioPosterMode(false));
4334-
}
4335-
4336-
return PromiseClass.all(exitPromises).then(() => this.enableAudioOnlyUI_());
4337-
}
4338-
4339-
// Disable Audio Only Mode
4340-
return PromiseClass.resolve().then(() => this.disableAudioOnlyUI_());
4341-
}
4342-
4316+
// Enable Audio Only Mode
43434317
if (value) {
4318+
const exitPromises = [];
4319+
4320+
// Fullscreen and PiP are not supported in audioOnlyMode, so exit if we need to.
43444321
if (this.isInPictureInPicture()) {
4345-
this.exitPictureInPicture();
4322+
exitPromises.push(this.exitPictureInPicture());
43464323
}
43474324

43484325
if (this.isFullscreen()) {
4349-
this.exitFullscreen();
4326+
exitPromises.push(this.exitFullscreen());
43504327
}
43514328

4352-
this.enableAudioOnlyUI_();
4353-
} else {
4354-
this.disableAudioOnlyUI_();
4329+
if (this.audioPosterMode()) {
4330+
exitPromises.push(this.audioPosterMode(false));
4331+
}
4332+
4333+
return Promise.all(exitPromises).then(() => this.enableAudioOnlyUI_());
43554334
}
4335+
4336+
// Disable Audio Only Mode
4337+
return Promise.resolve().then(() => this.disableAudioOnlyUI_());
43564338
}
43574339

43584340
enablePosterModeUI_() {
@@ -4391,44 +4373,27 @@ class Player extends Component {
43914373

43924374
this.audioPosterMode_ = value;
43934375

4394-
const PromiseClass = this.options_.Promise || window.Promise;
4395-
4396-
if (PromiseClass) {
4397-
4398-
if (value) {
4399-
4400-
if (this.audioOnlyMode()) {
4401-
const audioOnlyModePromise = this.audioOnlyMode(false);
4376+
if (value) {
44024377

4403-
return audioOnlyModePromise.then(() => {
4404-
// enable audio poster mode after audio only mode is disabled
4405-
this.enablePosterModeUI_();
4406-
});
4407-
}
4378+
if (this.audioOnlyMode()) {
4379+
const audioOnlyModePromise = this.audioOnlyMode(false);
44084380

4409-
return PromiseClass.resolve().then(() => {
4410-
// enable audio poster mode
4381+
return audioOnlyModePromise.then(() => {
4382+
// enable audio poster mode after audio only mode is disabled
44114383
this.enablePosterModeUI_();
44124384
});
44134385
}
44144386

4415-
return PromiseClass.resolve().then(() => {
4416-
// disable audio poster mode
4417-
this.disablePosterModeUI_();
4387+
return Promise.resolve().then(() => {
4388+
// enable audio poster mode
4389+
this.enablePosterModeUI_();
44184390
});
44194391
}
44204392

4421-
if (value) {
4422-
4423-
if (this.audioOnlyMode()) {
4424-
this.audioOnlyMode(false);
4425-
}
4426-
4427-
this.enablePosterModeUI_();
4428-
return;
4429-
}
4430-
4431-
this.disablePosterModeUI_();
4393+
return Promise.resolve().then(() => {
4394+
// disable audio poster mode
4395+
this.disablePosterModeUI_();
4396+
});
44324397
}
44334398

44344399
/**

src/js/tech/html5.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,8 @@ class Html5 extends Tech {
970970
videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
971971
}
972972

973-
if (window.performance && typeof window.performance.now === 'function') {
973+
if (window.performance) {
974974
videoPlaybackQuality.creationTime = window.performance.now();
975-
} else if (window.performance &&
976-
window.performance.timing &&
977-
typeof window.performance.timing.navigationStart === 'number') {
978-
videoPlaybackQuality.creationTime =
979-
window.Date.now() - window.performance.timing.navigationStart;
980975
}
981976

982977
return videoPlaybackQuality;

src/js/utils/dom-data.js

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,6 @@
33
* @module dom-data
44
*/
55

6-
import log from './log.js';
7-
import * as Guid from './guid.js';
8-
import window from 'global/window';
9-
10-
let FakeWeakMap;
11-
12-
if (!window.WeakMap) {
13-
FakeWeakMap = class {
14-
constructor() {
15-
this.vdata = 'vdata' + Math.floor(window.performance && window.performance.now() || Date.now());
16-
this.data = {};
17-
}
18-
19-
set(key, value) {
20-
const access = key[this.vdata] || Guid.newGUID();
21-
22-
if (!key[this.vdata]) {
23-
key[this.vdata] = access;
24-
}
25-
26-
this.data[access] = value;
27-
28-
return this;
29-
}
30-
31-
get(key) {
32-
const access = key[this.vdata];
33-
34-
// we have data, return it
35-
if (access) {
36-
return this.data[access];
37-
}
38-
39-
// we don't have data, return nothing.
40-
// return undefined explicitly as that's the contract for this method
41-
log('We have no data for this element', key);
42-
return undefined;
43-
}
44-
45-
has(key) {
46-
const access = key[this.vdata];
47-
48-
return access in this.data;
49-
}
50-
51-
delete(key) {
52-
const access = key[this.vdata];
53-
54-
if (access) {
55-
delete this.data[access];
56-
delete key[this.vdata];
57-
}
58-
}
59-
};
60-
}
61-
626
/**
637
* Element Data Store.
648
*
@@ -69,4 +13,4 @@ if (!window.WeakMap) {
6913
* @type {Object}
7014
* @private
7115
*/
72-
export default window.WeakMap ? new WeakMap() : new FakeWeakMap();
16+
export default new WeakMap();

src/js/utils/map.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/js/utils/set.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/api/api.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,17 @@ QUnit.test('component can be subclassed externally', function(assert) {
249249
const Component = videojs.getComponent('Component');
250250
const ControlBar = videojs.getComponent('ControlBar');
251251

252-
const player = new (videojs.extend(Component, {
253-
reportUserActivity() {},
252+
class TestComponent extends Component {
253+
reportUserActivity() {}
254254
textTracks() {
255255
return {
256256
addEventListener: Function.prototype,
257257
removeEventListener: Function.prototype
258258
};
259259
}
260-
}))({
260+
}
261+
262+
const player = new TestComponent({
261263
id() {},
262264
reportUserActivity() {}
263265
});
@@ -275,14 +277,15 @@ function testHelperMakeTag() {
275277

276278
QUnit.test('should extend Component', function(assert) {
277279
const Component = videojs.getComponent('Component');
278-
const MyComponent = videojs.extend(Component, {
280+
281+
class MyComponent extends Component {
279282
constructor() {
280283
this.bar = true;
281-
},
284+
}
282285
foo() {
283286
return true;
284287
}
285-
});
288+
}
286289

287290
const myComponent = new MyComponent();
288291

@@ -291,7 +294,8 @@ QUnit.test('should extend Component', function(assert) {
291294
assert.ok(myComponent.bar, 'the constructor function is used');
292295
assert.ok(myComponent.foo(), 'instance methods are applied');
293296

294-
const NoMethods = videojs.extend(Component);
297+
class NoMethods extends Component {}
298+
295299
const noMethods = new NoMethods({});
296300

297301
assert.ok(noMethods.on, 'should extend component with no methods or constructor');

0 commit comments

Comments
 (0)