Skip to content

Commit

Permalink
PBJS Core: call custom render func after loadscript if provided (#6422)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiegirault authored Apr 6, 2021
1 parent 5e94a65 commit 71fdd01
Showing 1 changed file with 11 additions and 6 deletions.
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`);
}
}

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

0 comments on commit 71fdd01

Please sign in to comment.