Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AMD (Asynchronous Module Definition) in require! #195

Closed
pioneer opened this issue Oct 30, 2012 · 12 comments
Closed

Support AMD (Asynchronous Module Definition) in require! #195

pioneer opened this issue Oct 30, 2012 · 12 comments

Comments

@pioneer
Copy link

pioneer commented Oct 30, 2012

It's worth for require! to support other module systems than RequireJS, such as AMD, as TypeScript does. Switching between CommonJS and AMD can be provided via compiler commandline options, for example. Some pieces of code that might be with require! and AMD support, using Dojo Toolkit:

Simple example:

# Livescript:
require! {
    dojo/dom
    dojo/dom-ready!
}
dom.by-id \helloworld .innerHTML = "Hello New World!"

# Javascript:
require(["dojo/dom", "dojo/domReady!"], function(dom, domReady){
  dom.byId("helloworld").innerHTML = "Hello New World!";
});

Require with parameters:

# Livescript
require! app, app/routes, {baseUrl: '', packages: [\dojo, \dijit, \dojox]}
# some code goes here

# Javascript:
require({baseUrl: "", packages: ["dojo", "dijit", "dojox"]},
    ["app", "app/routes"],
    function(app, routes) {
        // some code goes here
    }
);

or

# Livescript:
require! {
    "dojo/_base/declare"
    "dijit/_WidgetBase"
    "dijit/_TemplatedMixin"
    template: "dojo/text!./templates/SomeWidget.html"

   {
    base-url: ''
    packages: [\dojo, \dijit, \dojox,
               { name: \app, location: \app, map: {} }]
   }
}

# some code goes here

# Javascript:
require({
    baseUrl: "",
    packages: ["dojo", "dijit", "dojox",
               { name: "app", location: "app", map: {} }]
}, [
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!./templates/SomeWidget.html"
], function(declare, _WidgetBase, _TemplatedMixin, template) {
    // some code goes here
});

Define:

# Livescript:
define! {
  "dojo/_base/declare"
  "dijit/_WidgetBase"
  "dijit/_TemplatedMixin"
  template: "dojo/text!./templates/SomeWidget.html"
}

export! declare [_WidgetBase, _TemplatedMixin], {
    template-string: template
    #  your custom code goes here
}

# Javascript:
define([
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!./templates/SomeWidget.html"
], function(declare, _WidgetBase, _TemplatedMixin, template) {
    return declare([_WidgetBase, _TemplatedMixin], {
        templateString: template,
        // your custom code goes here
    });
});
@vendethiel
Copy link
Contributor

I really think this is going too far.
Ls already supports node-specific features (export from coco, altough useful in the browser and require!) and supporting a library itself is for me a no-go.

-1

@pioneer
Copy link
Author

pioneer commented Nov 13, 2012

According to http://requirejs.org/docs/whyamd.html#amdtoday, AMD isn't just Dojo-specific.

@vendethiel
Copy link
Contributor

True. But the syntax isn't always the same - require.js AFAIK doesn't return declare(....
Plus it dors not change my point : it's library-specific.

@pioneer
Copy link
Author

pioneer commented Nov 13, 2012

Sorry, it looks like my idea can be misunderstood. I suggested not to return declare, but just add export! keyword that should be compiled to return in case of AMD (though I think this feature is to be discussed).

@gkz gkz closed this as completed in c7c745b Jan 4, 2013
@vendethiel
Copy link
Contributor

Whoops

@pioneer
Copy link
Author

pioneer commented Jan 4, 2013

It seems this commit closes satyr/coco#195, but not the current issue.

@gkz gkz reopened this Jan 4, 2013
@kennknowles
Copy link

Any word on this? Some great libraries are being written in LiveScript that I would like to use in browser-based projects, which for me means AMD-based projects, but I am not sure how to proceed.

@gkz
Copy link
Owner

gkz commented Apr 16, 2013

I think the best solution is to use something like https://github.com/substack/node-browserify

ie. write it like it's a node project, and then use a tool to turn it into something that works in the browser

@michaelficarra
Copy link
Contributor

I recommend https://github.com/michaelficarra/commonjs-everywhere, it plays very nicely with LiveScript and other compile-to-JS languages.

@tiye
Copy link

tiye commented Apr 21, 2013

It would be nice if LiveScript works with commonjs-everywhere and with SourceMap support.
Reading code compiled from LiveScript is harder than from CoffeeScript.

@mehcode
Copy link

mehcode commented Apr 21, 2013

Just to throw something else in here. We write LiveScript commonjs modules then use grunt and https://github.com/anodynos/uRequire to convert them into AMD. The setup works great.

@vendethiel
Copy link
Contributor

Going to close for now. Feel free to bump if you have any idea for a good implementation that'd work without breaking anything else and without adding a lot of code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants