-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
custom namespacing [cleaned up commit] #257
Conversation
Thanks for fixing the commit @ojotoxy @protonate thoughts? |
You don't need to lookup pbjs in every code file, doing so in Otherwise this approach works great, thank you, please flatten commits and we'll merge it it. |
So to clarify, this change in the appnexus adapter (and everywhere else) is not needed:
As the pbjs var used here is the one defined in src/prebid.js It does seem necessary to look up the global var name at least once for most adapters, just to get the name for the JSONP callback. I'll try this out and make a new PR with it cleaned up. |
Ah, yes, in the case of JSONP callbacks it would be necessary. |
Can you explain what you mean by "the rest of the code will load in the same context", I don't see how this is true in modules. This snippet below from the appnexus adapter seems to break when the pbjs var is named something else. I don't see how it is expected that referring to pbjs here would use the variable defined in src/prebid.js. Modules have their own scope and won't see locals defined in other files. In src/prebid.js, "pbjs" is defined as a local.
Any thoughts on the best thing to do now? |
Yes, you are right, sorry for the confusion. There seems to be an issue with the TripleLife adapter when the dynamic name is not I've looked at this more closely now and am thinking we shouldn't burden the dev community with the use case of supporting a non-standard syntax (e.g. We could tokenize the global with I'm experimenting with using a Symbol and will put up a PR for consideration if that works out. |
Realistically, I think a global replacement of the token is not a bad idea. It could be done as the last compilation step. As long as the name used is very unique, it doesn't even need to surrounded with %%, thus not breaking dev tools. The source code could refer to a variable like PbjsGlobal (unlikely to ever conflict with anything) and a compilation step could transform that to pbjs or anything the user wants. |
Sounds good, want to update the PR with that approach? Following the adapterLoader approach we can set the dynamic name in package.json and use blockLoader to replace the |
Duplicate #293 |
This is how I implemented: #115
I am totally open to other ways of implementing this feature. I just want this feature to exist.
This is the "obvious" way of doing namespacing - allow a configurable field in constants.json where the global variable name can be chosen.
Then everywhere pbjs was used needs to lookup what the global var is called.