-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Changed the anonymous define into a named define #1064
Conversation
Changed the anonymous define into a named define so the script can still be included via script tag when using requirejs.
Thanks for the PR! Sorry if I'm missing something obvious here, but would you mind giving an example of what exactly this fixes? |
Hi! I hope that my example clarifies the intent of my pull request. Wether the module's name should be videojs or video, should better be decided by you. |
I actually don't have enough experience with AMD to confirm this. @jnwng, can you confirm this change at least doesn't break your AMD setup? |
i think underscore.js has a good rationale for naming versus not naming their module here, quoted below:
to put it simply, since so many third-party libraries refer to an explicit need for @csupnig's case is very much a corner-case, and i think there are quite a few more well-iterated arguments against naming modules (this and this), both of which lead me to advise against naming the module. this all being said, we explicitly set all of our modules to be anonymous because we have various legacy pieces working at the same time. we avoid name collisions all together through the use of anonymous modules, and we explicitly remove the named |
That's good feedback, thanks @jnwng. Is there no way we can determine the context that it's being loaded in? i.e. skip the define if we know it's not being used with AMD? Or what about just a try/catch? |
i didn't know this off the top of my head; i dug a little and found a few things:
the short of it is, no you cannot distinguish whether or not a module is being loaded via AMD or being included via a script tag. you can however determine whether or not its being loaded through AMD via Require.js. Require.js exposes a function called as for try/catch, it looks like require.js opts to catch errors internally to stop the loading of things, so a traditional try/catch block surrounding the define call won't be sufficient. you're allowed to specify a |
I'm not really sure what to do with this one. It sounds like there's no great option here. I tried adding a try/catch and like @jnwng said, no luck. Using the onError might be ok but it's not an event listener, it's an actual stored callback, meaning we might overwrite someone else's onError function. Any other opinions? |
@csupnig, what if we checked for a var like |
I think it would help in my specific use case, but it would be a very wonky solution. |
I agree it's wonky... I think what we'll do for now is close the issue and wait to see what other interest we get in it. Thanks again for putting this together though. One last thought I had was if there was a workaround (outside of video.js) where you modify define() so it catches this issue. Something like:
Also super wonky, but maybe it'd help anyone else that runs into this issue... |
Changed the anonymous define into a named define so the script can still be included via script tag when using requirejs.