I like the idea of optional dependencies.
It seems like we would want to think of the library as a module around the
external "openpgp.methodCall" rather than the "openpgp_packet_compressed"
level. Perhaps longterm that could be a good end goal for separated design,
but I think initially our goal should be to modularize the library as a
whole. Thoughts?
Aside from requiredjs not supporting optional dependencies it seems like we
don't really want to leave the actual modular definition up to the
consumer. It would be nice if requirejs did:
require('openpgp.js', {zlib: 'path/to/zlib', bzip: 'path/to/bzip' },
function(_openpgp) {
openpgp = _openpgp;
});
However, knowing what it does, it seems like the following is closer to how
it would be done there:
require('openpgp.js', function(_openpgp) {
_openpgp.setOptionalDependencies({zlib: 'path/to/zlib', bzip:
'path/to/bzip' });
openpgp = _openpgp;
});
It seems like tags.js is good at defining these modules when writing the
libraries but I'm not sure I understand the best way to consume it like we
would want here.
On Sun, Apr 14, 2013 at 9:47 AM, <[email protected]> wrote:
> > I also added an example using require.js. I haven't fully tested, but I
> > think this is the direction that best helps modularize openpgpjs.
>
> I think require.js is a step into the right direction, but it's missing a
> few features we might be interested in. Namely, it does not allow
> optional dependencies, which would be useful for compiling a trimmed
> down version of the library.
>
> I'd envision something along these lines:
> module('openpgp_packet_compressed',
> ['zlib', 'openpgp_packet'], // A list of mandatory dependencies
> ['lzma', 'bzip'], // optional dependencies
> function(zlib, openpgp_packet, lzma, bzip) {
>
> var exports = function() {
> this.tagType = 8;
> // ...
> if(bzip != undefined)
> // Compress as bzip
> // ...
> }
>
> return exports;
> })
>
> Later invoked as:
> module('some_other_module', ['openpgp_packet_compressed'],
> [], function(openpgp_packet_compressed) {
>
> var packet = new openpgp_packet_compressed();
> })
>
> I've written a small library that does things similarily
> https://github.com/dreamingofelectricsheep/tags.js
> _______________________________________________
>
> http://openpgpjs.org
>
_______________________________________________
http://openpgpjs.org