Lacking support for CommonJS
rileyjshaw opened this issue · comments
Operative plays nice with AMD but resorts to a global in CommonJS loaders. Here's an example of a Universal Module Definition that covers all bases.
Hmm yeh should probably get this in. Thanks for opening an issue! Up for putting together a PR?
@padolsey done! Sorry for the delay :)
Thanks!!
No worries :)
Sent from my iPhone
On Apr 20, 2015, at 3:46, James Padolsey notifications@github.com wrote:
Thanks!!
—
Reply to this email directly or view it on GitHub.
Hey @padolsey - bad news :(
Because some of the submodules (eg. OperativeContext.js) are relying on the global operative
, this still doesn't work well in a bundle. I see two routes from here:
- Remove checks for both AMD and CommonJS, create a global
operative
by default, and leave the Grunt concatenation untouched. - Rewrite the modules to use AMD or CommonJS, and bundle them with something like grunt-browserify.
Option 1 has the advantage of minimizing change to the library, and removes the need for more complex bundlers (it's just concatenated .js files). Option 2 has the advantage of allowing the library to be consumed transparently by any client, and removing an unnecessary global in bundled settings.
Sorry to bring this back up - I thought #34 was sufficient, but I hadn't considered the other files that are concatenated with operative.js...
I can make a PR for either option, just wanted to get your thoughts before moving ahead.
Ah, yep, I should have noticed that. Definitely up for option 2 if you have the time. The concatenation is a bit of a mess now.
Though option 2 has obvious benefits, lines like this might make it pretty hard to remodel. For the time being I think that unbreaking things quickly with a global is the right course of action.
Let me know what you think! Sorry this wasn't as easy as I'd initially thought.
(see #38)
That __run__
would only be exposed in the generated iframe, but I still agree that this all might be more trouble than it's worth (at least at the moment). Shall look into your PR.
(Closing for now; I would very much like to revisit this at some point though)