Jump to content

How To Write Proper MVC?


MrFish

Recommended Posts

Hello W3C, I've been doing web stuff for a while and a little spoiled since I haven't had to mess with MVC much. I'm writing a large javascript app that would be nice to have some kind of programming paradigm. Right now I'm just having trouble finding how to implement a controller that wouldn't just get in the way. I've written a basic test file tree viewer trying to find a way to add a controller to it. In the end I just set the controller of the model the ul or li object since it already has all the ui events like onclick. But I would still need to set the controller methods on the file inside the view where it creates the dom tree (see link). I'm also having trouble imagining a situation where it would be more convenient to have the view go through the controller or poll the controller with/for information. So lets say I want my file manager to run in a pane in my app. But there will also be a time where I want it to come up in a popup where clicking the folders and files will react differently with the model and view then the one in the pane. I guess this is where the controller comes in? Instead of having 2 slightly altered model classes or 2 slightly altered view classes I have 2 slightly altered controller classes that interacts with the ui events differently? Anyway Here is my attempt where I wasn't able to figure out how I should build my controller. http://jsbin.com/oso...javascript,live

Link to comment
Share on other sites

I've googled this topic and there is some material out there. I guess I never thought about it for Javascript. I guess if you consider your validators to be models?

Link to comment
Share on other sites

I think it is similar to what I am doing with game states (or levels) in JavaScript. I create a 'class' for each level or menu and use a normal array to hold the current states of the program. The last element in the array would be the current state. So if you had one state running and wanted to have an options menu pop up over that then you would just push that menu class on to the array of states.

Edited by astralaaron
Link to comment
Share on other sites

Well I'm still looking into it. I'll post an update on what I come up with if anyone is still interested.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...