autoload classes from one file

56 views
Skip to first unread message

markezic...@gmail.com

unread,
Aug 23, 2013, 8:27:36 AM8/23/13
to jsclas...@googlegroups.com
Hi,

how can I convert the following file definition using the autoload method?

file('/Areas/Main/Application/ControllerRequests.js')
            .requires('JS.Singleton')
            .provides('AccountControllerRequests', 'ApplicationControllerRequests');

i tried with:

autoload(/^(.*)ControllerRequests$/, {
            from: function () { return '/Areas/Main/Application/ControllerRequests.js'; },
            require: ['JS.Singleton']
        });

but the problem is that the code above will create 2 requests for ControllerRequests.js.

James Coglan

unread,
Aug 23, 2013, 10:05:39 AM8/23/13
to jsclas...@googlegroups.com
That's be design. An 'autoload' statement generates a separate package for every name that matches the regex, that's why it creates two modules in this case. The first code snippet you shared is how I would model this. 

markezic...@gmail.com

unread,
Aug 29, 2013, 4:09:02 AM8/29/13
to jsclas...@googlegroups.com

That's be design. An 'autoload' statement generates a separate package for every name that matches the regex, that's why it creates two modules in this case. The first code snippet you shared is how I would model this. 

Thanks for the reply. I separated the classes so that every class is within its own file and the autoload then worked flawlessly :)
Before I continue with my second question I have to congratulate you for the job that you've done with this wonderfull library. 
The ideas that you've used for the class dependency registration, class system, package building... are just brilliant... keep up the good work ;)

Now my second question:

I have a the following manifest.js

file('/Areas/Main/Framework/Helpers/ClassHelper.js')
    .requires('JS.Singleton')
    .provides('ClassHelper');

autoload(new RegExp('^Main.Controllers\.(.*)ControllerRequests$'), {
    from: function (name) {
name = name.replace('Main.', 'Main.Application.').replace(/\./g, '/');
return '/Areas/' + name + '.js';
    },
    require: ['JS.Singleton', 'ClassHelper']
});

When I try to require a class (for example Main.Controllers.AccountControllerRequests) in the browser everything works as expected:
 
but when I try to create a bundle with jsbuild the autoload registration does not work as expected.

Command:
jsbuild -m ../../../Scripts/js-class/loader-browser.js -m ../../../Areas/Main/Application/Manifest.js --root ../../../ -o paths Main.Controllers.AccountControllerRequests

the file  ../../../Areas/Main/Application/Manifest.js: contains the code above

Console output:
E:\SVN\BAF\trunk\BAF\BAF.Web\Scripts\js-class\core.js
E:\SVN\BAF\trunk\BAF\BAF.Web\Areas\Main\Framework\Helpers\ClassHelper.js
E:\Areas\Main\Application\Controllers\AccountControllerRequests.js

What do I have to do in order to change the last console input line to match the following line below?
E:\SVN\BAF\trunk\BAF\BAF.Web\Areas\Main\Application\Controllers\AccountControllerRequests.js 
Reply all
Reply to author
Forward
0 new messages