Move Trix explicitly on to the window object#236
Move Trix explicitly on to the window object#236lemonmade wants to merge 1 commit intobasecamp:masterfrom
window object#236Conversation
|
I am not sure if I like the idea of populating global |
|
Like I said, this is not an ideal solution, the best solution is a UND wrapper but the issue proposing that was closed. This at least clarifies that Trix needs to be on window given the way it is currently written/ bundled, and allows it to work in cases where the context in which the script is executed is not the global context. |
|
That is true. How the code references |
|
I think this is a reasonable compromise so 👍. Another minimal change would be to export module?.exports = TrixWhat do you think? |
|
Why not just properly include an UMD wrapper? |
|
@mitar see your own comment and #119 (comment) |
|
|
|
I'm open to supporting AMD too. If you're interested in adding "universal" support to this PR (or a new one), please do. |
|
No need for this anymore :) Thanks for the better fix! |
As mentioned in this issue, Trix currently does not work at all with node module loaders. The solution proposed in that PR specifically solved the issue for Webpack, but not for any bundler that wraps Trix in an IIFE (as most do). This is because the index file adds
Trixtothis, which is assumed to bewindow, and all other bundled files (themselves executed in IIFEs) assume the ability to access Trix somewhere in scope (which works when the originalthiswaswindow, but not when it is anything else).At Shopify, we're using a custom JavaScript bundle to be able to use npm packages. The only solution for us with Trix right now is to vendor it and make these changes manually.
Anyhow, this PR somewhat improves the situation by attaching Trix to
windowexplicitly. This is far from ideal — it would be much better to use a UMD wrapper so that it can be brought into a project using AMD, CJS, or globals. However, this is a smaller change that isn't too much of a departure from what's currently there.cc/ @javan