Skip to content

Commit

Permalink
use goog.module
Browse files Browse the repository at this point in the history
  • Loading branch information
dulmandakh committed Mar 8, 2022
1 parent 1507b1e commit 64df8fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion build/generateExterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if (assert.strict) {
const esprima = require('esprima');
const fs = require('fs');

const googModule = ['goog.module', 'goog.provide'];
// The annotations we will consider "exporting" a symbol.
const EXPORT_REGEX = /@(?:export|exportInterface|expose)\b/;

Expand Down Expand Up @@ -127,7 +128,7 @@ function dumpNode(node) {
*/
function isProvideNode(node) {
return isCallNode(node) &&
getIdentifierString(node.expression.callee) == 'goog.provide';
googModule.includes(getIdentifierString(node.expression.callee));
}


Expand Down
11 changes: 6 additions & 5 deletions lib/abr/ewma.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.abr.Ewma');
goog.module('shaka.abr.Ewma');
goog.module.declareLegacyNamespace();

goog.require('goog.asserts');
const {assert} = goog.require('goog.asserts');


/**
* @summary
* This class computes an exponentionally-weighted moving average.
*/
shaka.abr.Ewma = class {
exports = class Ewma {
/**
* @param {number} halfLife The quantity of prior samples (by weight) used
* when creating a new estimate. Those prior samples make up half of the
* new estimate.
*/
constructor(halfLife) {
goog.asserts.assert(halfLife > 0, 'expected halfLife to be positive');
assert(halfLife > 0, 'expected halfLife to be positive');

/**
* Larger values of alpha expire historical data more slowly.
Expand All @@ -44,7 +45,7 @@ shaka.abr.Ewma = class {
* new estimate.
*/
updateAlpha(halfLife) {
goog.asserts.assert(halfLife > 0, 'expected halfLife to be positive');
assert(halfLife > 0, 'expected halfLife to be positive');
this.alpha_ = Math.exp(Math.log(0.5) / halfLife);
}

Expand Down
15 changes: 8 additions & 7 deletions lib/abr/ewma_bandwidth_estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.abr.EwmaBandwidthEstimator');
goog.module('shaka.abr.EwmaBandwidthEstimator');
goog.module.declareLegacyNamespace();

goog.require('shaka.abr.Ewma');
const Ewma = goog.require('shaka.abr.Ewma');


/**
Expand All @@ -16,22 +17,22 @@ goog.require('shaka.abr.Ewma');
* different half-lives.
*
*/
shaka.abr.EwmaBandwidthEstimator = class {
exports = class EwmaBandwidthEstimator {
/** */
constructor() {
/**
* A fast-moving average.
* Half of the estimate is based on the last 2 seconds of sample history.
* @private {!shaka.abr.Ewma}
* @private {!Ewma}
*/
this.fast_ = new shaka.abr.Ewma(2);
this.fast_ = new Ewma(2);

/**
* A slow-moving average.
* Half of the estimate is based on the last 5 seconds of sample history.
* @private {!shaka.abr.Ewma}
* @private {!Ewma}
*/
this.slow_ = new shaka.abr.Ewma(5);
this.slow_ = new Ewma(5);

/**
* Number of bytes sampled.
Expand Down

0 comments on commit 64df8fc

Please sign in to comment.