Skip to content

Commit 99ba911

Browse files
authored
perf: utils refactor & cleanup (#595)
* perf: utils refactor (array, assign, playlist utils) * perf: utils refactor (cloudinary, css-prefix, dom, find) * perf: utils refactor (cloudinary, css-prefix, dom, find) * perf: utils refactor (groupBy, matches) * perf: utils refactor (find, omit, get, object, positioning, tests, playButton) * chore: bundlesize * perf: utils refactor (webpack loaders) * perf: utils refactor (startsWith, camelize) * perf: utils refactor (throttle, types) * perf: utils refactor (isObject) * chore: cleanup * perf: utils refactor (hasCodec) * chore: export
1 parent 9938b27 commit 99ba911

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+180
-556
lines changed

docs/scripts.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
/* eslint no-var: "off", vars-on-top: "off", curly: "off", no-extend-native: "off" */
22

3-
// String.startsWith() polyfill
4-
if (!String.prototype.startsWith) {
5-
String.prototype.startsWith = function (searchString, position) {
6-
position = position || 0;
7-
return this.substr(position, searchString.length) === searchString;
8-
};
9-
}
10-
11-
// URLSearchParams.get() polyfill
12-
if (!window.URLSearchParams) {
13-
window.URLSearchParams = window.URLSearchParams || function (searchString) {
14-
var self = this;
15-
self.searchString = searchString;
16-
self.get = function (name) {
17-
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString);
18-
19-
if (results === null) {
20-
return null;
21-
}
22-
23-
return decodeURI(results[1]) || 0;
24-
};
25-
};
26-
}
27-
283
// true on /localhost or /anything.local
294
var isLocal = window.location.hostname === 'localhost' || window.location.hostname.substring(window.location.hostname.lastIndexOf('.', window.location.hostname.lastIndexOf('.')) + 1) === 'local';
305

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
{
6363
"path": "./dist/cld-video-player.light.min.js",
64-
"maxSize": "125kb"
64+
"maxSize": "130kb"
6565
},
6666
{
6767
"path": "./lib/cld-video-player.js",

src/components/qualitySelector/qualitySelector.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* global dashjs */
22
import '../../plugins/videojs-http-source-selector/plugin';
3-
import { findIndex } from '../../utils/find';
43

54
import './quality-selector.scss';
65

@@ -59,7 +58,7 @@ const qualitySelector = {
5958
if (val !== undefined) {
6059
this.selected = val;
6160
if (val === true) {
62-
let selectedIdx = findIndex(player.qualityLevels().levels_, (l => l.id === this.id));
61+
const selectedIdx = player.qualityLevels().levels_?.findIndex(l => l.id === this.id);
6362
player.qualityLevels().selectedIndex_ = selectedIdx;
6463
player.qualityLevels().trigger({
6564
type: 'change',

src/components/shoppable-bar/layout/bar-layout.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import videojs from 'video.js';
3-
import { elMatches } from 'utils/matches';
43

54
const dom = videojs.dom || videojs;
65
const Component = videojs.getComponent('Component');
@@ -84,7 +83,7 @@ class ShoppableBarLayout extends Component {
8483
if (this.options_.autoClose && this.options_.startState.indexOf('open') !== -1) {
8584
setTimeout(() => {
8685
// Keep it open while hovered
87-
if (!elMatches(this.contentEl_, ':hover')) {
86+
if (!this.contentEl_.matches(':hover')) {
8887
this.togglePanel(false);
8988
} else {
9089
this.contentEl_.addEventListener('mouseleave', () => {

src/components/shoppable-bar/panel/shoppable-panel-item.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import videojs from 'video.js';
2-
import { elMatches } from 'utils/matches';
32

43
const ClickableComponent = videojs.getComponent('ClickableComponent');
54
const dom = videojs.dom || videojs;
@@ -25,7 +24,7 @@ class ShoppablePanelItem extends ClickableComponent {
2524
event.preventDefault();
2625
event.stopPropagation();
2726

28-
if (!elMatches(this.el_, `.dragged .${CLD_SPBL_ITEM}`)) {
27+
if (!this.el_.matches(`.dragged .${CLD_SPBL_ITEM}`)) {
2928
// Prevent click event if dragged
3029
this.options_.clickHandler(event);
3130
}

src/components/shoppable-bar/panel/shoppable-panel.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import videojs from 'video.js';
2-
import { assign } from 'utils/assign';
3-
import { throttle } from 'utils/throttle';
2+
import throttle from 'lodash/throttle';
43
import { parseTime } from 'utils/time';
54
import ShoppablePanelItem from './shoppable-panel-item';
65
import ImageSource from '../../../plugins/cloudinary/models/image-source';
@@ -52,7 +51,7 @@ class ShoppablePanel extends Component {
5251
const cloudinaryConfig = this.player_.cloudinary.cloudinaryConfig();
5352
return this.options.products.map(product => {
5453
if (product.onHover && typeof product.onHover.args === 'object') {
55-
product.onHover.args.transformation = assign({},
54+
product.onHover.args.transformation = Object.assign({},
5655
this.options.transformation,
5756
product.onHover.args.transformation
5857
);
@@ -68,7 +67,7 @@ class ShoppablePanel extends Component {
6867
};
6968
const imageSource = new ImageSource(product.publicId, {
7069
cloudinaryConfig: cloudinaryConfig,
71-
transformation: assign({}, this.options.transformation, product.transformation)
70+
transformation: Object.assign({}, this.options.transformation, product.transformation)
7271
});
7372
return {
7473
imageSrc: imageSource,

src/extended-events.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import videojs from 'video.js';
22
import EventEmitter from 'events';
3-
import { assign } from 'utils/assign';
4-
import { isPlainObject } from 'utils/type-inference';
3+
import isObject from 'lodash/isObject';
54
import { PLAYER_EVENT } from './utils/consts';
65

76
const EVENT_DEFAULTS = {
@@ -203,8 +202,8 @@ const normalizeEventsParam = (events, defaults) => {
203202
normalized = events.reduce((agg, item) => {
204203
const eventDefaults = defaults[item] || {};
205204

206-
if (isPlainObject(item)) {
207-
agg[item.type] = assign({}, eventDefaults, item);
205+
if (isObject(item)) {
206+
agg[item.type] = Object.assign({}, eventDefaults, item);
208207
} else {
209208
agg[item] = eventDefaults;
210209
}

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import 'assets/styles/main.scss';
2+
import pick from 'lodash/pick';
23
import VideoPlayer from './video-player';
34
import createVideoPlayerProfile from './video-player-profile';
4-
import { assign } from 'utils/assign';
5-
import { pick, convertKeysToSnakeCase } from './utils/object';
5+
import { convertKeysToSnakeCase } from './utils/object';
66
import { CLOUDINARY_CONFIG_PARAM } from './video-player.const';
77

88
const getConfig = (playerOptions = {}, cloudinaryConfig) => {
99
const snakeCaseCloudinaryConfig = pick(convertKeysToSnakeCase(playerOptions), CLOUDINARY_CONFIG_PARAM);
1010

1111
// pick cld-configurations and assign them to cloudinaryConfig
12-
return assign(playerOptions, {
12+
return Object.assign(playerOptions, {
1313
cloudinaryConfig: cloudinaryConfig || snakeCaseCloudinaryConfig
1414
});
1515
};

src/plugins/autoplay-on-scroll/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { isElementInViewport } from 'utils/positioning';
22
import { sliceProperties } from 'utils/slicing';
3-
import { assign } from 'utils/assign';
43

54
const defaults = {
65
fraction: 0.5,
@@ -9,7 +8,7 @@ const defaults = {
98

109
class AutoplayOnScrollPlugin {
1110
constructor(player, opts = {}) {
12-
opts = assign({}, defaults, opts);
11+
opts = Object.assign({}, defaults, opts);
1312

1413
this.player = player;
1514
let _options = sliceProperties(opts, 'fraction');

src/plugins/cloudinary/common.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import videojs from 'video.js';
2-
import { assign } from 'utils/assign';
2+
import omit from 'lodash/omit';
33
import { sliceAndUnsetProperties } from 'utils/slicing';
4-
import { isString, isPlainObject } from 'utils/type-inference';
4+
import isObject from 'lodash/isObject';
5+
import isString from 'lodash/isString';
56
import { URL_PATTERN } from './models/video-source/video-source.const';
67
import { createCloudinaryLegacyURL } from '@cloudinary/url-gen/backwards/createCloudinaryLegacyURL';
78
import Transformation from '@cloudinary/url-gen/backwards/transformation';
8-
import { omit } from '../../utils/object';
99

1010
const normalizeOptions = (publicId, options, { tolerateMissingId = false } = {}) => {
11-
if (isPlainObject(publicId)) {
12-
const _options = assign({}, publicId);
11+
if (isObject(publicId)) {
12+
const _options = Object.assign({}, publicId);
1313

1414
publicId = sliceAndUnsetProperties(_options, 'publicId').publicId;
1515

@@ -18,7 +18,7 @@ const normalizeOptions = (publicId, options, { tolerateMissingId = false } = {})
1818
}
1919

2020
if (options) {
21-
options = assign({}, _options, options);
21+
options = Object.assign({}, _options, options);
2222
}
2323
}
2424

0 commit comments

Comments
 (0)