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

Asked

Viewed 196 times

4

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

Each route has 40 to 70 lines of code and one evento bindado. Write everything down in one callback from app is turning into a beautiful macaroni because these events (this.bind) do not function in the scope of the route, only in the global scope, so they mix with the uses, arounds, etc..

My intention is to do something similar to modularization of Express.js + Express Load. Like loading the arounds, before, helpers and runs in a main.js file and routes separately.

How can I do that? Require.js?

Example of the structure of my code:

(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)
  • http://stackoverflow.com/questions/17348123/using-sammyjs-with-requirejs

  • Managed to solve?

  • @durtto, yes. I created my own ajax loading framework. I got tired.

  • I understand. Try to elaborate an answer to your question. So other people can be helped.

  • Solved your problem?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.