I would like to see what Nils suggested with RequireJS or AMD
(Asynchronous Module Definition). There is also CommonJS which is what
Node.js uses.

For example here is a library, that is able to be used with three
different methods:
1) AMD
2) Node.js/CommonJS
3) global

https://github.com/caolan/async/blob/master/lib/async.js#L933

On 03/25/2013 11:58 PM, Sean Colyer wrote:
> I agree it would be good to move out of the global space. We can take a
> couple of different paths to accomplish this.
> 
> Option one -- Use augmentation to maintain file-by-file independence. We
> could presumably use a form like:
> var openpgp = (function(context) { .. })(openpgp || {});
> in each of our js files to build the openpgp object up ad-hoc.  I think
> the major downside to this is that references that are now to our more
> static calls (like in crypto/cfb
> folders: openpgp_crypto_generateSessionKey) will all have to be update,
> i.e.: openpgp.openpgp_crypto_generateSessionKey
> 
> Option two -- Concatenate all the files and then wrap the entire thing.
> This is similar to what jQuery does with intro and outro
> (https://github.com/jquery/jquery/tree/master/src). We have to make sure
> the files are built in the same order, but I think it is the path of
> least resistance. We could avoid some of the updating associated with
> option one. It could also be worthwhile here to switch to a build system
> closer to what jQuery uses with node/grunt to accomplish some of these
> tasks.
> 
> I think Option two is what we are better positioned for and also a good
> path forward.
> 
> Thoughts?
> Sean
> 
> On Sun, Mar 17, 2013 at 6:46 PM, Nils Kenneweg
> <[email protected] <mailto:[email protected]>> wrote:
> 
> Am 16.03.2013 16:36, schrieb Tankred Hase:
>> This has only partly to do with this porblem. But Is anyone else
>> concerned about the fact that all functions of the library are
>> appended to the global object?
> 
> Yep. Not really good practice, is it? Should also make the usage with
> things like requirejs difficult as far as I can see it.
> 
> Even though changing it might be a hard refactoring work, it might be
> worth it.
> 
> Greets,
> Nils
> 
>     _______________________________________________
> 
>     http://openpgpjs.org
> 
> 
> 
> 
> _______________________________________________
> 
> http://openpgpjs.org
> 

_______________________________________________

http://openpgpjs.org

Reply via email to