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

Why not just use AMD define #2

Closed
guybedford opened this issue Dec 12, 2013 · 3 comments
Closed

Why not just use AMD define #2

guybedford opened this issue Dec 12, 2013 · 3 comments
Labels

Comments

@guybedford
Copy link

  define('main', function(require, exports) {
  });

is entirely supported by AMD, and concatenates for builds.

If you really wanted to push this technique, could you not push it with the existing toolset?

What isn't supported by RequireJS or Almond with the above that necessitates writing a new tool?

@inikulin
Copy link
Owner

Because with current approach you can create numerous isolated module containers in your page, e.g.:

var Navigation = new Mods();

Navigation.define('Menu', function() {
    //...
});

var Content = new Mods();

Content.define('ArticlePopup', function() {
});

However you can always fallback to the desired (AMD-like) approach:

var MyApp = new Mods();

window.define = function(name, mod) {
     MyApp.define(name, mod);
};

window.get = function(name) {
     return MyApp.get(name);
};

If it's really critical to you, I can add this functionality into the lib.

@guybedford
Copy link
Author

What use case does isolated module trees solve over a single module tree?

It looks very interesting though - and an amazingly small footprint, fascinating code. Thanks for explaining.

@inikulin
Copy link
Owner

Thank you for your interest in mods.
In big apps you can have pretty complicated pieces of code, which are not interacting with each other. E.g. you have a full-featured code editor on one page of your site. And a common runtime for the whole site. Obviously you don't need to include code editor to the pages which doesn't require it. So, it's just a way to organize your code. Big applications is not monolith, moreover different subsystems may be mantained by different teams, So, splitting your code base into such module containers seems reasonable for me, moreover it helped us a lot on our huge project (70k+ LOC of JS). With existing solutions(e.g. RequireJS) I felt that we have a really over-engineered things happening for such a simple stuff.

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

No branches or pull requests

2 participants