Giter Site home page Giter Site logo

modulejs.run about modulejs HOT 4 CLOSED

dmgr avatar dmgr commented on June 2, 2024
modulejs.run

from modulejs.

Comments (4)

lrsjng avatar lrsjng commented on June 2, 2024

@dmgr just use modulejs.require() for that..

from modulejs.

dmgr avatar dmgr commented on June 2, 2024

It doesn't work, because if you have this order of code snippets:

  modulejs.require('lib_a', function(lib_a) {
    console.log('using lib_a');
  });

  modulejs.define('lib_a', function() {
    console.log('lib_a loaded');
    return {};
  });

You will have a:
Uncaught Error: [modulejs-32] id not defined "lib_a"

The hypothetical "modulejs.run" function might work thanks to observers working in "modulejs.define" function and when that observer will recognize that all libraries are defined to run particular code snippet defined by "modulejs.run" method, it will fire it.
Of course "module.require" can work like that so then "modulejs.run" wouldn't be necessary.

from modulejs.

lrsjng avatar lrsjng commented on June 2, 2024

That will not work at all, as require expects a single id argument only, no callback.

I think the best way to run your code is after all js is loaded, for example:

document.addEventListener('DOMContentLoaded', function () {

    var app = modulejs.require('main');
    app.start();
});

or with jQuery:

jQuery(function () {

    var app = modulejs.require('main');
    app.start();
});

but I understand your request now..

from modulejs.

dmgr avatar dmgr commented on June 2, 2024

Yes, I thought about that solution and I think it will be done using that workaround.
Anyway, something like:

    modulejs.require(['lib_a', 'lib_b'], function(lib_a, lib_b) {
        lib_a.start();
    })

or/and:

    modulejs.require(['lib_a', 'lib_b'], function() {
        var lib_a = modulejs.require('lib_a');
        lib_a.start();
    })

in addition to:

    var lib_a = modulejs.require('lib_a');
    lib_a.start();

would be cool ;)

from modulejs.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.