Is there a JavaScript MVC (micro-)framework?

Viewed 72552

Are there any client-side JavaScript MVC (micro-)frameworks?

I have a rather complicated HTML form, and it would benefit from the MVC pattern.

I imagine a good solution would provide the following:

  • Model and View update the Controller when values change (Observer pattern)
  • Populate the model from the form data when the page loads
  • Populate the form from the model when the model changes

Ajax, comet, JSONP and all that jazz are serious overkill.

30 Answers

I think this one looks like something you should check out: http://knockoutjs.com/

(As a silverlight / wpf programmer this was the library that made me finally start learning javascript. It is based on the Model-View-View-Model (MVVM) pattern, as for me right now seems like a good choise!)

Stapes.js

Full disclosure: i'm the author of this library :)

If you're looking for something really tiny (1.5kb minified / gzipped) have a look, and tell me if you like it.

If your requirements are really simple, you could write your own simple MVC like Alex Netkachov did.

His examples are built on dojo (Note: they don't work for me on his page because of a missing dojo.js file), but you could follow the pattern in plain Javascript.

The popular ActionScript MVC framework PureMVC was recently ported to JavaScript. I haven't had a chance to try it out yet, but I am confident it's good.

UPDATE 2016: Sammy.js seems to be abandoned.

Have a look at Sammy.js

Text from the site:

A small webframework with class.

  • SMALL Sammy's core is only 16K compressed and 5.2K compressed and gzipped
  • MODULAR Sammy is built on a system of plugins and adapters . Only include the code you need. It's also easy to extract your own code into reusable plugins.
  • CLEAN The entire API was designed to be easy to understand and read. Sammy tries to encourage good encapsulation and application design.
  • FUN What's the real point of development if its not enjoyable. Sammy tries to follow the MATZ approach. It is optimized for developer happiness.

There was a key-value binding JavaScript framework called "Coherent", which was inspired by Apple's Cocoa Bindings. The framework has been bought by Apple, but there is still an old copy at http://github.com/trek/coherentjs/tree/master.

I'm going to pipe up here too - AFrameJS works with jQuery, MooTools and Prototype.

Related