Skip to content

Commit

Permalink
Prefer const over let.
Browse files Browse the repository at this point in the history
A coming update to the Google eslint config will require using "const"
over "let".  This makes that one change to isolate the big changes.

Change-Id: I7d0974c3ae15c53cc45a6b07bf9f6586e2d34aca
  • Loading branch information
TheModMaker committed May 8, 2019
1 parent a453095 commit c813897
Show file tree
Hide file tree
Showing 178 changed files with 3,602 additions and 3,558 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = {
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"prefer-const": ["error", {"ignoreReadBeforeAssign": true}],
// }}}

// "Possible error" rules in "eslint:recommended" that need options: {{{
Expand Down
2 changes: 1 addition & 1 deletion demo/asset_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AssetCard {
}
}

for (let drm of asset.drm) {
for (const drm of asset.drm) {
switch (drm) {
case KeySystem.WIDEVINE:
this.addFeatureIcon_('widevine', 'Widevine DRM');
Expand Down
4 changes: 2 additions & 2 deletions demo/cast_receiver/receiver_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ ShakaReceiver.prototype.init = function() {
shaka.polyfill.installAll();

/** @type {HTMLMediaElement} */
let video = /** @type {HTMLMediaElement} */
const video = /** @type {HTMLMediaElement} */
(document.getElementById('video'));
goog.asserts.assert(video, 'Video element should be available!');
this.video_ = video;

/** @type {!shaka.ui.Overlay} */
let ui = this.video_['ui'];
const ui = this.video_['ui'];
goog.asserts.assert(ui, 'UI should be available!');

// Make sure we don't show extra UI elements we don't need on the TV.
Expand Down
10 changes: 5 additions & 5 deletions demo/common/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ const ShakaDemoAssetInfo = class {
// Construct a generic object with the values of this object, but with the
// proper formatting.
const raw = {};
for (let key in this) {
for (const key in this) {
const value = this[key];
if (value instanceof Map) {
// The built-in JSON functions cannot convert Maps; this converts Maps
// to objects.
const replacement = {};
replacement['__type__'] = 'map';
for (let entry of value.entries()) {
for (const entry of value.entries()) {
replacement[entry[0]] = entry[1];
}
raw[key] = replacement;
Expand Down Expand Up @@ -317,7 +317,7 @@ const ShakaDemoAssetInfo = class {
});
}
if (this.extraConfig) {
for (let key in this.extraConfig) {
for (const key in this.extraConfig) {
config[key] = this.extraConfig[key];
}
}
Expand Down Expand Up @@ -361,11 +361,11 @@ const ShakaDemoAssetInfo = class {
static fromJSON(raw) {
// This handles the special case for Maps in toJSON.
const parsed = {};
for (let key in raw) {
for (const key in raw) {
const value = raw[key];
if (value && typeof value == 'object' && value['__type__'] == 'map') {
const replacement = new Map();
for (let key in value) {
for (const key in value) {
if (key != '__type__') {
replacement.set(key, value[key]);
}
Expand Down
4 changes: 2 additions & 2 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ShakaDemoConfig {
// All robustness fields of a given type are set at once.
this.addDatalistInput_(name, robustnessSuggestions, (input) => {
// Add in any common drmSystem not currently in advanced.
for (let drmSystem of commonDrmSystems) {
for (const drmSystem of commonDrmSystems) {
if (!(drmSystem in advanced)) {
advanced[commonDrmSystems] = {
distinctiveIdentifierRequired: false,
Expand All @@ -152,7 +152,7 @@ class ShakaDemoConfig {
}
}
// Set the robustness.
for (let drmSystem in advanced) {
for (const drmSystem in advanced) {
advanced[drmSystem][valueName] = input.value;
}
shakaDemoMain.configure('drm.advanced', advanced);
Expand Down
24 changes: 12 additions & 12 deletions demo/demo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


/** @namespace */
let ShakaDemoUtils = {};
const ShakaDemoUtils = {};

/**
* Goes through the various values in shaka.extern.PlayerConfiguration, and
Expand All @@ -37,8 +37,8 @@ ShakaDemoUtils.runThroughHashParams = (callback, config) => {
// This exists for legacy reasons; the previous demo page had some hash values
// set to names that did not match the names of their corresponding config
// object name.
let overridden = [];
let configOverride = (hashName, configName) => {
const overridden = [];
const configOverride = (hashName, configName) => {
overridden.push(configName);
callback(hashName, configName);
};
Expand All @@ -58,16 +58,16 @@ ShakaDemoUtils.runThroughHashParams = (callback, config) => {
// This is to remove ambiguity in situations where there are two objects in
// the config that share a key with the same name, without wasting space by
// pointlessly adding namespace information to every value.
let added = [];
let collisions = [];
let findCollisions = (object) => {
for (let key in object) {
const added = [];
const collisions = [];
const findCollisions = (object) => {
for (const key in object) {
if (added.includes(key) && !collisions.includes(key)) {
collisions.push(key);
}
added.push(key);

let value = object[key];
const value = object[key];
if (typeof value != 'number' && typeof value != 'string' &&
typeof value != 'boolean') {
findCollisions(value);
Expand All @@ -82,16 +82,16 @@ ShakaDemoUtils.runThroughHashParams = (callback, config) => {
// discard any 'bufferBehind=' values from old hashes.

// Now automatically do other config values.
let handleConfig = (object, accumulated) => {
for (let key in object) {
const handleConfig = (object, accumulated) => {
for (const key in object) {
let hashName = key;
let configName = accumulated + key;
const configName = accumulated + key;
if (overridden.includes(configName)) continue;
if (collisions.includes(key)) {
hashName = configName;
}

let value = object[key];
const value = object[key];
if (typeof value == 'number' || typeof value == 'string' ||
typeof value == 'boolean') {
callback(hashName, configName);
Expand Down
2 changes: 1 addition & 1 deletion demo/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ShakaDemoSelectInput extends ShakaDemoInput {
this.input_.classList.add('mdl-textfield__input');
this.extra_.classList.add('mdl-textfield__label');
this.extra_.setAttribute('for', this.input_.id);
for (let value of Object.keys(values)) {
for (const value of Object.keys(values)) {
const option = document.createElement('option');
option.textContent = values[value];
option.value = value;
Expand Down
16 changes: 8 additions & 8 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ShakaDemoMain {
const localization = this.controls_.getLocalization();
const UNKNOWN_LOCALES = shaka.ui.Localization.UNKNOWN_LOCALES;
localization.addEventListener(UNKNOWN_LOCALES, (event) => {
for (let locale of event['locales']) {
for (const locale of event['locales']) {
this.loadUILocale_(locale);
}
});
Expand Down Expand Up @@ -458,7 +458,7 @@ class ShakaDemoMain {
}

// Does the asset contain a playable mime type?
let mimeTypes = [];
const mimeTypes = [];
if (asset.features.includes(shakaAssets.Feature.WEBM)) {
mimeTypes.push('video/webm');
}
Expand Down Expand Up @@ -516,7 +516,7 @@ class ShakaDemoMain {

const obj = await response.json();
const map = new Map();
for (let key in obj) {
for (const key in obj) {
map.set(key, obj[key]);
}

Expand Down Expand Up @@ -873,7 +873,7 @@ class ShakaDemoMain {
params.push('uilang=' + this.getUILocale());

const navButtons = document.getElementById('nav-button-container');
for (let button of navButtons.childNodes) {
for (const button of navButtons.childNodes) {
if (button.nodeType == Node.ELEMENT_NODE &&
button.classList.contains('mdl-button--accent')) {
params.push('panel=' + button.textContent);
Expand Down Expand Up @@ -980,12 +980,12 @@ class ShakaDemoMain {
// Add a click listener to display this container, and hide the others.
const switchPage = () => {
// This element should be the selected one.
for (let child of navButtons.childNodes) {
for (const child of navButtons.childNodes) {
if (child.nodeType == Node.ELEMENT_NODE) {
child.classList.remove('mdl-button--accent');
}
}
for (let child of contents.childNodes) {
for (const child of contents.childNodes) {
if (child.nodeType == Node.ELEMENT_NODE) {
this.hideNode_(child);
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ class ShakaDemoMain {
setUpVersionString_() {
const version = shaka.Player.version;
let split = version.split('-');
let inParen = [];
const inParen = [];

// Separate out some special terms into parentheses after the rest of the
// version, to make them stand out visually.
Expand Down Expand Up @@ -1125,7 +1125,7 @@ class ShakaDemoMain {
}


let shakaDemoMain = new ShakaDemoMain();
const shakaDemoMain = new ShakaDemoMain();


/**
Expand Down
6 changes: 3 additions & 3 deletions demo/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ShakaDemoSearch {
break;
case ShakaDemoSearch.TermType.FEATURE:
// Only this term should be in the desired features.
for (let term of others) {
for (const term of others) {
const index = this.desiredFeatures_.indexOf(
/** @type {shakaAssets.Feature} */ (term));
if (index != -1) {
Expand Down Expand Up @@ -208,7 +208,7 @@ class ShakaDemoSearch {
searchContainer.addRow(null, null);
const nullOption = 'Unspecified';
const valuesObject = {};
for (let term of choices) {
for (const term of choices) {
if (type == 'DRM') {
// The internal names of the keysystems aren't very readable, so use a
// common name instead.
Expand Down Expand Up @@ -304,7 +304,7 @@ class ShakaDemoSearch {
if (this.desiredSource_ && asset.source != this.desiredSource_) {
return false;
}
for (let feature of this.desiredFeatures_) {
for (const feature of this.desiredFeatures_) {
if (feature == shakaAssets.Feature.STORED) {
if (!asset.isStored()) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/abr/ewma.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ shaka.abr.Ewma = function(halfLife) {
* @param {number} value
*/
shaka.abr.Ewma.prototype.sample = function(weight, value) {
let adjAlpha = Math.pow(this.alpha_, weight);
let newEstimate = value * (1 - adjAlpha) + adjAlpha * this.estimate_;
const adjAlpha = Math.pow(this.alpha_, weight);
const newEstimate = value * (1 - adjAlpha) + adjAlpha * this.estimate_;

if (!isNaN(newEstimate)) {
this.estimate_ = newEstimate;
Expand All @@ -67,6 +67,6 @@ shaka.abr.Ewma.prototype.sample = function(weight, value) {
* @return {number}
*/
shaka.abr.Ewma.prototype.getEstimate = function() {
let zeroFactor = 1 - Math.pow(this.alpha_, this.totalWeight_);
const zeroFactor = 1 - Math.pow(this.alpha_, this.totalWeight_);
return this.estimate_ / zeroFactor;
};
4 changes: 2 additions & 2 deletions lib/abr/ewma_bandwidth_estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ shaka.abr.EwmaBandwidthEstimator.prototype.sample = function(
return;
}

let bandwidth = 8000 * numBytes / durationMs;
let weight = durationMs / 1000;
const bandwidth = 8000 * numBytes / durationMs;
const weight = durationMs / 1000;

this.bytesSampled_ += numBytes;
this.fast_.sample(weight, bandwidth);
Expand Down
20 changes: 10 additions & 10 deletions lib/abr/simple_abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ shaka.abr.SimpleAbrManager.prototype.chooseVariant = function() {
// Get sorted Variants.
let sortedVariants = SimpleAbrManager.filterAndSortVariants_(
this.config_.restrictions, this.variants_);
let currentBandwidth = this.bandwidthEstimator_.getBandwidthEstimate(
const currentBandwidth = this.bandwidthEstimator_.getBandwidthEstimate(
this.config_.defaultBandwidthEstimate);

if (this.variants_.length && !sortedVariants.length) {
Expand All @@ -131,12 +131,12 @@ shaka.abr.SimpleAbrManager.prototype.chooseVariant = function() {
let chosen = sortedVariants[0] || null;

for (let i = 0; i < sortedVariants.length; ++i) {
let variant = sortedVariants[i];
let nextVariant = sortedVariants[i + 1] || {bandwidth: Infinity};
const variant = sortedVariants[i];
const nextVariant = sortedVariants[i + 1] || {bandwidth: Infinity};

let minBandwidth = variant.bandwidth /
const minBandwidth = variant.bandwidth /
this.config_.bandwidthDowngradeTarget;
let maxBandwidth = nextVariant.bandwidth /
const maxBandwidth = nextVariant.bandwidth /
this.config_.bandwidthUpgradeTarget;
shaka.log.v2('Bandwidth ranges:',
(variant.bandwidth / 1e6).toFixed(3),
Expand Down Expand Up @@ -238,18 +238,18 @@ shaka.abr.SimpleAbrManager.prototype.suggestStreams_ = function() {
this.startupComplete_ = true;
} else {
// Check if we've left the switch interval.
let now = Date.now();
let delta = now - this.lastTimeChosenMs_;
const now = Date.now();
const delta = now - this.lastTimeChosenMs_;
if (delta < this.config_.switchInterval * 1000) {
shaka.log.v2('Still within switch interval...');
return;
}
}

let chosenVariant = this.chooseVariant();
let bandwidthEstimate = this.bandwidthEstimator_.getBandwidthEstimate(
const chosenVariant = this.chooseVariant();
const bandwidthEstimate = this.bandwidthEstimator_.getBandwidthEstimate(
this.config_.defaultBandwidthEstimate);
let currentBandwidthKbps = Math.round(bandwidthEstimate / 1000.0);
const currentBandwidthKbps = Math.round(bandwidthEstimate / 1000.0);

shaka.log.debug(
'Calling switch_(), bandwidth=' + currentBandwidthKbps + ' kbps');
Expand Down
Loading

0 comments on commit c813897

Please sign in to comment.