/app.js

Simple JS MVC

Primary LanguageJavaScriptMIT LicenseMIT

AppJS

All of the current MVC JS frameworks where FAR too complicated. So I made this super simple 'framework' for creating rapid MVC apps in JS.

Dependencies

Examples

Super simple example for example for displaying 'default' content.

app.extend("home",{
	
	/* test for required loaded modules before we load this one */
	require: ['models','controllers','views'],
	
    /* This is our 'constructor' */
    _construct: function(){
		
		/* add our views */
		app.views.add("home", "<h1>Welcome to Satmap</h1>");
		
        /* we can register a model */
        app.models.add("page",{ title: "", content: ""});

        /* we register a 'controller' */
        app.controllers.register({controller: "/", callback: 
			function(req){ 
				app.render(app.home.page());
			} 
		});
		
    },

    /* register a function to be used by out controller */
    page: function(){ 
        return app.views.show("home", app.models.get("page"));
    }

});

if the above is loaded app.home.page() will be triggered when the hashbang is empty.

an example to show model data in a rendered view.

app.extend("home",{
	
	/* test for required loaded modules before we load this one */
	require: ['models','controllers','views'],
	
    /* This is our 'constructor' */
    _construct: function(){
		
		/* add our views */
		app.views.add("home", "<h1><%= title %></h1><p><%= content %></p>");
		
        /* we can register a model */
        app.models.add("page",{ title: "Welcome to satmap", content: "there is some content here."});

        /* we register a 'controller' */
        app.controllers.register({controller: "/", callback: 
			function(req){ 
				app.render(app.home.page());
			} 
		});
		
    },

    /* register a function to be used by out controller */
    page: function(){ 
        return app.views.show("home", app.models.get("page"));
    }

});

will render the model values into our view. see _.js templating for more information.

Development

This project will progress as my use of it increases. Expect binding from objects to dom elements to be the next feature and the loading of remote 'views'.

I'll accept pull requests on nice features or bug fixes, but the aim of this project is to keep things lite. I'm not trying to build a replacement for ember.