Liu-Young / pagedown

Automatically exported from code.google.com/p/pagedown
Other
0 stars 0 forks source link

Support asynchronous module definition #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Supporting asynchronous module definition [1] would allow to use 
CommonJS-compliant asynchronous javascript loaders like requirejs [2] on the 
client side.

This also allows to declare dependencies between modules, and to ensure that 
some module is loaded before an other.

This would look like this for Markdown.Converter:

``` Javascript
define(function() {
    // return Converter here
});

And for Markdown.Editor:

define(['Markdown.Converter'], function(Converter) {
    // return Editor here
});

And in the client code:

require(['Markdown.Converter', 'Markdown.Editor'], function(Converter, Editor) {
     // ...
});

With non-CommonJs compat:

var Markdown;

function doExport(factory) {
    if (typeof 'define' === 'function' && typeof 'require' === 'function') {
        define.call(this, factory);
    } else {
        Markdown.Converter = factory();
    }
}
doExport(function() {
     // ... return Converter
});

[1] http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition [2] http://requirejs.org/


Original issue reported on code.google.com by `arnaud.lb` on 4 Aug 2011 at 5:09
GoogleCodeExporter commented 9 years ago
I was somewhat expecting this request :)

I'll look at it.

Original comment by b...@stackoverflow.com on 5 Aug 2011 at 5:30

GoogleCodeExporter commented 9 years ago
This would be great for using pagedown in GitHub's gollum software.

Original comment by m...@bootstraponline.com on 7 Jun 2012 at 4:32