Please recommend titanium project structure using CommonJS

I am starting a new Titanium application and want to use best practices and avoid memory leaks from get mode. I am new to CommonJS, as well as to the Titanium platform in general.

Unfortunately, it seems that all of the sample applications for titanium surround on Ti.include("/lib/module")instead of the newer recommended best practice require("/lib/module") .

I am worried about memory consumption from using CommonJS. From the CommonJS Modules in the Titanium documentation , it says that the modules will be cached, does that mean that if I ever get access to the module, all these functions suddenly remain in memory, even if they go beyond?

I started a new application with the following structure

/ctrl           # Model/UI controllers
/lib            # libraries (common + 3rd party)
/ui             # UI forms
/model          # DAL objects for data store

Here, my main application has one view of the toolbar style, which is freely structured as follows:

(function() {
    var getMenuItem = require("/ui/main").getMenuItem;
    var win = Titanium.UI.createWindow({
        title:'Main',
        backgroundColor:'#fff'
    });
    var nav = Ti.UI.iPhone.createNavigationGroup({
        window:win
    });
    var sect;
    var data = [];
    sect = Ti.UI.createTableViewSection();
    data.push(sect);
    sect.add(getMenuItem("Customers",
        require("/ctrl/account").createCustMainWindow));
    sect.add(getMenuItem("Schedules",
        require("/ctrl/schedule").createScheduleMainWindow));
    sect.add(getMenuItem("Settings"));
    var menu = Titanium.UI.createTableView({
        style: Ti.UI.iPhone.TableViewStyle.GROUPED,
        data:data
    });
    win.add(menu);
    menu.addEventListener('click',function(e) {
        if (e.rowData.createWindow) {
            var win = e.rowData.createWindow(nav);
            nav.open(win);
        }
    });
    var navWindow = Titanium.UI.createWindow();
    navWindow.add(nav);
    navWindow.open();
})();

Any guidance on the proper design of the project is appreciated.

+5
source share
3 answers

This is a community that develops a program that uses a module template, and also looks through a developer’s blog to find Forging series that have samples designed primarily using a module template.

+2
source

I use require (), and I have a long start of require () at the beginning of the project, which may be one of the largest Titanium projects.

, , tousands . , , .

0

AFAIK , CommonJS, , . , .

factory. , , , NavGroup, .

Xcode, , , , . ( 1/3 ).

0

All Articles