How to modularize an app made in Sammy.js with Require.js or "module pattern"?

4

I have an app (mobile app) written in Sammy.js with 4 routes.

Each route has 40 to 70 lines of code and a evento bindado . Writing everything in a single callback of app is turning into a beautiful pasta because these events ( this.bind ) do not work in the scope of the route, only in the global scope, hence they mix with uses , arounds , etc.

I intend to do something similar to the Express.js + Express Load modularization. Type arounds , before , helpers and runs into a main .js file and the routes separately.

How can I do this? Require.js?

Example of my code structure:

(function($) {

    var app = $.sammy(appCallback);

    function appCallback() {

        this.use('Template');
        this.element_selector = '#partials';

        this.around(callback)

        this.get('/#rota1', //callback)
        this.get('/#rota2', //callback)
        this.get('/#rota3', //callback)
        this.get('/#rota3', //callback)

        this.bind('algum-evento-da-rota1', //callback)
        this.bind('algum-evento-da-rota2', //callback)
        this.bind('algum-evento-da-rota3', //callback)
        this.bind('algum-evento-da-rota4', //callback)

    }

    //run aplication
    app.run('#/');

})(jQuery)
    
asked by anonymous 17.02.2015 / 01:04

0 answers