JavascriptMVC
Encyclopedia
JavaScriptMVC is an open-source Rich Internet Application
Rich Internet application
A Rich Internet Application is a Web application that has many of the characteristics of desktop application software, typically delivered either by way of a site-specific browser, via a browser plug-in, independent sandboxes, extensive use of JavaScript, or virtual machines...

 framework based on jQuery
JQuery
jQuery is a cross-browser JavaScript library designed to simplify the client-side scripting of HTML. It was released in January 2006 at BarCamp NYC by John Resig...

 and OpenAjax. It extends those libraries with a model–view–controller architecture and tools for testing and deployment. As it does not depend on server components, it can be combined with any web service interface and server-side language like ASP.NET
ASP.NET
ASP.NET is a Web application framework developed and marketed by Microsoft to allow programmers to build dynamic Web sites, Web applications and Web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages ...

, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, or Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

.

History

The first release of JavaScriptMVC was published in May 2008. JavaScriptMVC 2.0 became stable in June 2009 and is based directly on jQuery, mainly to keep the code size small and to focus on its unique features. Version 3.0 was released in December 2010.

Controller

A controller is a list of functions that get called back when the appropriate event happens. The name of the function provides a description of when the function should be called. By naming functions in the correct way, Controller recognizes them as Actions and hook them up in the correct way, for example:


$.Controller.extend('TodosController',{
".todo mouseover": function(el, ev){
el.css("backgroundColor","red")
},
".todo mouseout": function(el, ev){
el.css("backgroundColor","")
},
"#create_todo click" : function{
this.find("ol").append("New Todo");
}
});


In a controller you can also handle OpenAjax events, for example:


$.Controller.extend('TodosController',{
"main.test subscribe": function(ev, publisherData){
// TODO: do something
},
"other.event subscribe": function(ev, publisherData){
// TODO: do something
}
});

View

JavaScriptMVC uses EJS templates to render HTML data in controllers and inject them into the DOM. The syntax was inspired by ERuby
ERuby
eRuby is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP, JSP and PHP.-Usage:eRuby allows Ruby code to be embedded within a pair of delimiters...

and is similar to PHP or other server-side template engines.

For example file "test.ejs" ( data = [ "Hello", "World" ] ):



    <% for( var i=0, var len = data.length; i < len; i++ ) { %>
  • <%= data[i] %>

  • <% } %>



      produces the following "output":


      • Hello

      • World



      Tests

      JavaScriptMVC also comes with a comprehensive test plug-in that supports classic unit tests for models, as well as functional test, that are required to deal with event driven architectures. Tests can be run on the command line with Rhino, using Selenium and during development with the integrated test console pop-up window.

      External links

      The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK