Skip to content

Commit

Permalink
Pbjs Core: avoid import all from utils in src/ files (#7466)
Browse files Browse the repository at this point in the history
* adloader: not importing * from utils
* ajax: not importing * from utils
* AnalyticsAdapter: not importing * from utils
* adapterManager: not importing * from utils
* auction: not importing * from utils
* bidfactory: not importing * from utils
* config: not importing * from utils
* cpmBucketManager: not importing * from utils
* prebid: not importing * from utils
* Renderer: not importing * from utils
* storageManager: not importing * from utils
* targeting: not importing * from utils
* userSync: not importing * from utils
* videoCache: not importing * from utils
  • Loading branch information
pm-harshad-mane authored Sep 28, 2021
1 parent 38c353a commit 467ad51
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 270 deletions.
12 changes: 6 additions & 6 deletions src/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import CONSTANTS from './constants.json';
import { ajax } from './ajax.js';
import { logMessage, _each } from './utils.js';

const events = require('./events.js');
const utils = require('./utils.js');

const {
EVENTS: {
Expand Down Expand Up @@ -123,22 +123,22 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
}
};

utils._each(_handlers, (handler, event) => {
_each(_handlers, (handler, event) => {
events.on(event, handler);
});
} else {
utils.logMessage(`Analytics adapter for "${global}" disabled by sampling`);
logMessage(`Analytics adapter for "${global}" disabled by sampling`);
}

// finally set this function to return log message, prevents multiple adapter listeners
this._oldEnable = this.enableAnalytics;
this.enableAnalytics = function _enable() {
return utils.logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`);
return logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`);
};
}

function _disable() {
utils._each(_handlers, (handler, event) => {
_each(_handlers, (handler, event) => {
events.off(event, handler);
});
this.enableAnalytics = this._oldEnable ? this._oldEnable : _enable;
Expand All @@ -158,6 +158,6 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
_enableCheck = false;
}

utils.logMessage(`event count sent to ${global}: ${_eventCount}`);
logMessage(`event count sent to ${global}: ${_eventCount}`);
}
}
18 changes: 10 additions & 8 deletions src/Renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { loadExternalScript } from './adloader.js';
import * as utils from './utils.js';
import {
logError, logWarn, logMessage, deepAccess
} from './utils.js';
import find from 'core-js-pure/features/array/find.js';
const moduleCode = 'outstream';

Expand All @@ -25,7 +27,7 @@ export function Renderer(options) {
this.cmd = [];
this.push = func => {
if (typeof func !== 'function') {
utils.logError('Commands given to Renderer.push must be wrapped in a function');
logError('Commands given to Renderer.push must be wrapped in a function');
return;
}
this.loaded ? func.call() : this.cmd.push(func);
Expand All @@ -44,7 +46,7 @@ export function Renderer(options) {
if (this._render) {
this._render.apply(this, renderArgs)
} else {
utils.logWarn(`No render function was provided, please use .setRender on the renderer`);
logWarn(`No render function was provided, please use .setRender on the renderer`);
}
}

Expand All @@ -53,7 +55,7 @@ export function Renderer(options) {
this.cmd.unshift(runRender) // should render run first ?
loadExternalScript(url, moduleCode, this.callback);
} else {
utils.logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`);
logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`);
runRender()
}
}.bind(this) // bind the function to this object to avoid 'this' errors
Expand All @@ -80,7 +82,7 @@ Renderer.prototype.handleVideoEvent = function({ id, eventName }) {
this.handlers[eventName]();
}

utils.logMessage(`Prebid Renderer event for id ${id} type ${eventName}`);
logMessage(`Prebid Renderer event for id ${id} type ${eventName}`);
};

/*
Expand All @@ -92,7 +94,7 @@ Renderer.prototype.process = function() {
try {
this.cmd.shift().call();
} catch (error) {
utils.logError('Error processing Renderer command: ', error);
logError('Error processing Renderer command: ', error);
}
}
};
Expand Down Expand Up @@ -126,11 +128,11 @@ function isRendererPreferredFromAdUnit(adUnitCode) {
}

// renderer defined at adUnit level
const adUnitRenderer = utils.deepAccess(adUnit, 'renderer');
const adUnitRenderer = deepAccess(adUnit, 'renderer');
const hasValidAdUnitRenderer = !!(adUnitRenderer && adUnitRenderer.url && adUnitRenderer.render);

// renderer defined at adUnit.mediaTypes level
const mediaTypeRenderer = utils.deepAccess(adUnit, 'mediaTypes.video.renderer');
const mediaTypeRenderer = deepAccess(adUnit, 'mediaTypes.video.renderer');
const hasValidMediaTypeRenderer = !!(mediaTypeRenderer && mediaTypeRenderer.url && mediaTypeRenderer.render)

return !!(
Expand Down
Loading

0 comments on commit 467ad51

Please sign in to comment.