0

I'm new to Javascript and I'm having troubles understanding the following piece of code. I have read this post (https://stackoverflow.com/a/60669635/9867856) which suggests that mifosXComponents.js and mifosXStyles.js are being passed as arguments into the function function(componentsInit){...}, but isn't componentsInit a single function that returns a promise? How come two .js files are converted into a function? I'm confused.

require(['mifosXComponents.js', 'mifosXStyles.js'], function (componentsInit) {
        componentsInit().then(function(){
            require(['test/testInitializer'], function (testMode) {
                if (!testMode) {
                    angular.bootstrap(document, ['MifosX_Application']);
                }
            });
        });
    });
megamonium
  • 463
  • 3
  • 7

1 Answers1

0

If you require two modules (as per example) then RequireJS will:

  • load them async;
  • load their dependencies;
  • inject the modules to you callback, each as separate argument.

So you have a mistake in your code, your callback will receive actually two arguments, so you need to have two parameters:

// require two modules async,
// when they are loaded,
// they are injected to your callback
require(['mifosXComponents.js', 'mifosXStyles.js'], function (mifosXComponents, mifosXStyles) {
    // now you can use both modules,
    // seems that first one is a function which returns promise,
    // but I have no idea what is the second one :)
    mifosXComponents().then(function(){
        require(['test/testInitializer'], function (testMode) {
            if (!testMode) {
                angular.bootstrap(document, ['MifosX_Application']);
            }
        });
    });
});
Damian Dziaduch
  • 2,107
  • 1
  • 15
  • 16