Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBJS Core: call custom render func after loadscript if provided #6422

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ export function Renderer(options) {

// use a function, not an arrow, in order to be able to pass "arguments" through
this.render = function () {
const renderArgs = arguments
const runRender = () => {
if (this._render) {
this._render.apply(this, renderArgs)
} else {
utils.logWarn(`No render function was provided, please use .setRender on the renderer`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this happening frequently? should it throw an event for analytics adapters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. If the external script is standalone it can handle everything itself but that would be recommended to set a renderer

}
}

if (!isRendererPreferredFromAdUnit(adUnitCode)) {
// we expect to load a renderer url once only so cache the request to load script
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}`);
}

if (this._render) {
this._render.apply(this, arguments) // _render is expected to use push as appropriate
} else {
utils.logWarn(`No render function was provided, please use .setRender on the renderer`);
runRender()
}
}.bind(this) // bind the function to this object to avoid 'this' errors
}
Expand Down