By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Javascript MVC example(s) wanted

P: n/a
I am after opend source small, middle or large example programs thay use MVC
pattern coded Javascript.

Many thanks in advance,

Aaron

Jul 22 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jul 22, 8:27 am, "Aaron Gray" <ang.use...@gmail.comwrote:
I am after opend source small, middle or large example programs thay use MVC
pattern coded Javascript.
The traditional Smalltalk MVC does translate to JavaScript reasonably
easily. Whether or not a naive translation is a good idea is a big
question. I don't think it is.

Having a Data Access Layer (DAL) to encapsulate all the
XMLHttpRequests is a good idea. This layer is the only layer that
knows anything about HTTP or any other types of communication. This
layer can do some processing on the returned data from the server to
comply with the DALs stated API.

Having a Model layer is a good idea. This is the only layer that talks
with the DAL. The model layer knows business logic and implements the
observer pattern.

The part of MVC that causes me pause in the browser is the VC
distinction. I don't really think they are very clearly separated. The
main issue is how the strategy pattern part of MVC will be
implemented. Because JavaScript objects are dynamic, you can replace
property function-values of an object. This is something you cannot do
in Java for example. I don't know about Smalltalk. So in JavaScript
instead of replacing a reference in the view layer to a controller
object, you can just replace a particular function of the view object
itself. Also I don't find I take advantage of the strategy pattern
part of MVC frequently.
I usually design a program as

DOM
===========================
Widget |
------------| bootstrap.js
Model |
---------------------------
DAL
===========================
Server
The bootstrap.js file starts the feature testing, calls the Model to
populate itself, calls the widgets to start themselves and sends
references where the widget should insert itself in the DOM and
references to models the widget should observe.

It isn't so important that the layers do what the the traditional
"MVC" says they should. What is important is that each layer does what
its documentation says it does. For a very simple little widget the
three JavaScript layers could all be combined into one object.

Colin Moock's "Essential ActionScript 2.0" has a good discussion of
MVC. The best one I have read. The code is not in JavaScript, of
course, and he is very keen on classes but it is an indication of how
programmers will likely start writing code with ECMAScript 4. I won't.
The site of all those interface definitions. Ugg. You can download
that code from his site. Chapter 18 and some chapters around it will
likely be your interest.

"MVC" doesn't seem to be a big thing in browser scripting. That could
mean it isn't very useful or comes in such a different shape it is not
called "MVC". I think that usually MVC is just too heavy for the
requirements in the browser.

Peter
Jul 22 '08 #2

P: n/a
On Jul 22, 11:27*am, "Aaron Gray" <ang.use...@gmail.comwrote:
I am after opend source small, middle or large example programs thay use MVC
pattern coded Javascript.

Many thanks in advance,

Aaron
TIBCO, http://www.tibco.com/devnet/gi/getting_started.jsp, has an MVC
javascript framework (free). Check it out. While I agree for the most
part with Peter Michaux's comments, there are certain problems in
maintaining a large site with many coders that an MVC javascript
framework solves. Features get added to pages that sometimes cause
three or four different inputs to update or read from the same data
object. If the original page is written using MVC, this is quite
maintainable. Else it becomes a labyrinth, a Rube Goldberg machine
that is extremely painful to trace.

So, a very light MVC javascript framework can be written that can't be
written in other languages due to the javascript features Peter
mentioned (recursion helps too). TIBCO has an interface builder and
it's framework is not lightweight but may help you in writing your
own.

Bob
Jul 23 '08 #3

P: n/a
"beegee" <bg*****@gmail.comwrote in message
news:7b**********************************@z66g2000 hsc.googlegroups.com...
>On Jul 22, 11:27 am, "Aaron Gray" <ang.use...@gmail.comwrote:
>I am after opend source small, middle or large example programs thay use
MVC
pattern coded Javascript.
>TIBCO, http://www.tibco.com/devnet/gi/getting_started.jsp, has an MVC
javascript framework (free). Check it out. While I agree for the most
Not quite what I was looking for.

Thanks anyway,

Aaron
Jul 25 '08 #4

P: n/a
On Jul 22, 11:27 am, "Aaron Gray" <ang.use...@gmail.comwrote:
I am after opend source small, middle or large example programs thay use MVC
pattern coded Javascript.
Jemplate, a javascript implementation of perl's Template::Toolkit:

http://search.cpan.org/~rkrimen/Jemp...ib/Jemplate.pm

It is very flexible and can be used in many more ways than the page
above indicates.

trwww
Jul 29 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.