Reputation: 109
I have small requirment. I am just started working on simple SPA application. My requirements are to be write class in on .js file and i should able to call individual class in another .js file.
in brief, I have Search,Order and Customer class in one .js file.
*globals define*/
define(function(require){
...
return search;
});
define(function(require){
...
return order;
});
define(function(require){
...
return customer;
});
i want to call any one the above module.Is there any solution for this.?
Thanks,
Shiva
Upvotes: 0
Views: 317
Reputation: 2954
This way is not allowed. There are other solutions to this problem.
Modules in Durandal are handled by the AMD library RequireJS. In the documentation of the library it says:
One module per file.: Only one module should be defined per JavaScript file, given the nature of the module name-to-file-path lookup algorithm. Multiple modules will be grouped into optimized files by the optimization tool, but you should only use the optimization tool to place more than one module in a file.
As it describes, one option is to optimize multiple modules (multiple files) into one file. (Optimization doc)
Or you could define one module with multiple objects inside as its described in this stackoverflow answer. Using this approach you will not be able to load the objects separatedly, so you will always need to load search, order
and customer
objects even if you need only one.
Upvotes: 2