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

UMD seems to be not quite clear for cases when you need multiple dependencies or none #135

Open
SergeyLastochkin opened this issue Jun 9, 2018 · 1 comment

Comments

@SergeyLastochkin
Copy link

SergeyLastochkin commented Jun 9, 2018

Provided UMD templates follow assumption that module "definedInTemplate" is dependent on module "b".

But how should UMD-compliant systems look like when module "definedInTemplate" is dependent on a FEW modules like "a", "b", "c"?

Or how to express in UMD-compliant way a case where module "definedInTemplate" is not dependent on any modules at all?

Also, regarding template for jQuery plugin - what if that plugin dependent not only on JQuery but on, for example, root, or other modules? Do you provide those in order of factory(jQuery, root, a, b, c); or as factory(a, b, c, root, jQuery);

@danielFHcode
Copy link

  1. To use multiple dependencies you simply pass to the function more libraries, like so:
    • define(['b', 'c', 'jequery'], factory);
    • module.exports = factory(require('b'), require('c'), require('jequery'));
    • root.definedInTemplate = factory(root.b, root.c, root.jQuery);
  2. As for the use of 'root', you're right, it is not realy accounted for. But you could modify the template so that you bind the root to the function:
     // replace
     factory()
     //with
     (factory.bind(root))()
    Then you can use 'this' within the function:
    function factory () {
        console.log(this);
        // expected output: the root object
    }
  3. For a module with no libraries, there is a template at the bottom of this file.

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

2 participants