treant-js icon indicating copy to clipboard operation
treant-js copied to clipboard

Please Remove Global Raphael Dependency

Open machineghost opened this issue 8 years ago • 1 comments

To put it simply, window.Raphael is so 1999 ;)

In all seriousness, module systems are an established part of Javascript development in 2016 ... so much so that there are three different competing standards (AMD, CommonJS, and ES6). Luckily, even if you have no interest in using any of these systems yourself, you can still support users who do just by adding a bit of boilerplate to your library.

The UMD project specifies several ways of doing this, but most likely you'd want to adopt the "CommonJS Strict" pattern, which supports both AMD and CommonJS. This pattern can be found at: https://github.com/umdjs/umd/blob/master/templates/commonjsStrict.js (simply replace 'b' in that example with 'raphael'). If you adopt this pattern module-less users who provide window.Raphael will still be able to use Treant as if nothing changed, but AMD/CommonJS users will be able to use their packaging system, instead of the window global, to provide Raphael.

(As a side note, you don't need to worry about ES6 because it's not implemented anywhere yet. This means anyone using it is using a tool like Webpack, and those tools are perfectly capable of translating AMD/CommonJS in to ES6.)

machineghost avatar Sep 01 '16 23:09 machineghost