JavaScriptMVC

From Infogalactic: the planetary knowledge core
Jump to: navigation, search
JavaScriptMVC
192px
Developer(s) Justin B. Meyer, Brian Moschel
Initial release May 2008; 16 years ago (2008-05)
Stable release 3.3 / July 23, 2013; 10 years ago (2013-07-23)
Written in JavaScript
Operating system Cross-platform
License MIT License[1]
Website <strong%20class= "error"><span%20class="scribunto-error"%20id="mw-scribunto-error-1">Lua%20error%20in%20Module:Wd%20at%20line%20405:%20invalid%20escape%20sequence%20near%20'"^'. http://<strong%20class="error"><span%20class="scribunto-error"%20id="mw-scribunto-error-1">Lua%20error%20in%20Module:Wd%20at%20line%20405:%20invalid%20escape%20sequence%20near%20'"^'.Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).

JavaScriptMVC is an open-source rich Internet application framework based on jQuery 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, Java, Perl, PHP, Python, or Ruby.

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. CanJS, JavaScriptMVC's extracted MVC parts, were released in April 2012.

Controller

A controller is a list of functions that gets 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, the Controller recognizes them as Actions and hooks them up correctly, for example:

 $.Controller('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");
   }
 });

A controller can also handle OpenAjax events, for example:

 $.Controller('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 and is similar to PHP or other server-side template engines.

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

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

produces the following "output":

<ul>
 <li>Hello</li>
 <li>World</li>
</ul>

Model

The Model class provides basic functionality to organize the application's data layer.

 $.Model('Todo',{
  findAll: '/todos',
  findOne: '/todos/{id}',
  create: '/todos',
  update: '/todos/{id}',
  destroy : '/todos/{id}'
 },{});

Tests

JavaScriptMVC also comes with a comprehensive test plug-in that supports classic unit tests for models, as well as functional tests, 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.

References

  1. Lua error in package.lua at line 80: module 'strict' not found.

External links

<templatestyles src="Asbox/styles.css"></templatestyles>

<templatestyles src="Asbox/styles.css"></templatestyles>