Deferred module dependency loading

Let’s say, I have 5 view modules dependency, and I want to load those module until needed.
I can’t pre-load those dependency as normally do, because the content of the modules will be generated by server based on the value supplied by user. How do I do that?

For example:
`
define([], function() {

var layout = {
	view: 'button', value: 'button', click: function() {
		require(['views/module1'], function(module) {
			//won't work. scope does not recognized
			this.$scope.ui(module);
		});
	}		
}

return {
	$ui: layout
}

});
`

Hello,

won’t work. scope does not recognized

You need to bind the callback to this object to maintain proper this reference:

var layout = {
	    view: 'button', value: 'button', click: function() {
	        require(['views/module1'], webix.bind(function(module) {
                    //such notation initializes windows
	            this.$scope.ui(module).show();
	        }, this));
	    }
	};

But as far as I see, the problem is that you want to query the server.

the content of the modules will be generated by server based on the value supplied by user

Then you may consider requring the module normally, but calling its methods when needed:

//views/module1  - the one that communicates server
define([], function() {
    return {
          getStructure:function(param){
               //send value supplied by user to server
               return webix.ajax(url?param=param);
          }
    }
});

//main view
define([
    "views/module1"
], function(m1) {

var layout = {
    view: 'button', value: 'button', click: function() {
        m1.getStructure(param).then(function(text, data){
                var module = data.json();
                this.$scope.ui(module).show();
        });
    }       
}

return { $ui: layout}
});

how I can create code highlight?

@Evgen88 the syntax is similar to the standard markdown, but while a single line of code can be written within the backtick (`) symbols, the code block should be enclosed with the three tildes:

~~~

/*Some code*/

~~~