Repository navigation
Update tooltip.js - #19541
Update tooltip.js#19541
Conversation
Don't reference `Tether` via attachment to `window`, with the update one can import bootstrap providing the dependencies in webpack with:
```
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Tether: 'tether',
});
```
Then inside one's own bootstrap/globals, `import 'bootstrap';` will simply work, and $/jQuery can be used from there.
I had wanted to do this, but also expose jQuery, Tether, etc when in development build in my code, but if I provide `window.Tether`, I can't then expose it to the outside...
match project's style check
| * Tether - http://github.hubspot.com/tether/ | ||
| */ | ||
| if (window.Tether === undefined) { | ||
| if (typeof Tether === 'undefined') { |
There was a problem hiding this comment.
Why not just : if (Tether === undefined) ?
Your JSPerf prove it's faster than using typeof
There was a problem hiding this comment.
@Johann-S That will throw an exception if Tether isn't defined...
if (someUndefinedValue === undefined) console.log('success')
// Uncaught ReferenceError someUndefinedValue is not defined
//this would work, but sloppier than the typeof
try {
if (Tether){}
} catch(err) {
throw new Error('Bootstrap tooltips require Tether (http://github.hubspot.com/tether/');
}|
@vsn4ik in your example You will see... Since Not to mention that the test in this case is really contrived, as it is only run a single time when the file in question is loaded, not millions of iterations. |
|
@bardiharborow @Johann-S Do we need this? I'm unclear if this helps us at all. |
|
I can't see any reason why we shouldn't merge this and close #20745. The issue here is that we want our code to work when Tether is loaded at both |
Don't reference
Tethervia attachment towindow, with the update one can import bootstrap providing the dependencies in webpack with:Then inside one's own bootstrap/globals,
import 'bootstrap';will simply work, and $/jQuery can be used from there.I had wanted to do this, but also expose jQuery, Tether, etc when in development build in my code, but if I provide
window.Tether, I can't then expose it to the outside...