PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jul 13, 2020 12:08 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 12:39 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
I've found a pretty good artcile on implementing MVC in JS, using the ExtJS framework:
http://savvyduck.blogspot.com/2008/01/j ... s-mvc.html

While it seems good enough, I've noticed some issues (considering the MVC approach):
1) (the most important) - the View class changes the Model state by calling the documentModel.setTemp( this.documentItemName, value, true);. I think that the View should just fire an event captured by the Controller, which in turn should change the Model state.

2) The Model instance is globally defined (easy to fix), should be created in the Controller and injected into the View.

Except these things, what's your opinion about this code?

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 2:41 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 3:02 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
I would disagree with the term "MVC flavor" to describe that, more like "sort of like MVC". I would say thats one of the most important parts of being MVC.

Interesting link. I had heard about javascript MVC but I traditionally view it as part of the presentation, that opens up interesting questions as to whether you can have "MVC" within your view within any language? Like an MVC application, but you use components in the view that themselves are mini-MVC applications. (or since it runs on the client VS the server you could look at it like a duplicate application, which makes me think about code generation).


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 3:30 pm 
Offline
DevNet Master
User avatar

Joined: Sun Jan 21, 2007 12:06 am
Posts: 4135
Well, HTTP request-response has an MVC structure, with your MVC application playing the model and performing the business logic. Database communication has an MVC structure with the query as the controller, the database handling the business logic, and your records as the view. I'm sure we could break down other elements into MVC structures. It's existed since before it existed. lol

The issue comes in where you differentiate input => logic => output structure from pure MVC, as we see it. If you break it down to input-logic-output, then the model, view, and controller are all MVC structures. The controller gets a request, gets it's response from the model and view, and returns output. The model gets a request from the controller, gets and format data, and outputs it to the controller. View takes data as input, formats and processes it, and outputs it to the controller.

Eh. My head hurts now.


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 4:25 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Last edited by VladSun on Thu Jan 13, 2011 6:09 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 4:32 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 5:50 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 5:53 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
Another intersting article to read http://osteele.com/archives/2004/08/web-mvc

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 5:54 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 6:30 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 8:10 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 9:14 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Thu Jan 13, 2011 10:35 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Fri Jan 14, 2011 9:18 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Right I meant the view should be read only in regards to reading not writing to the model. Well in fact I meant the view should not be writing to anything but the response object.

Just to be clear I didn't cherry pick those to support my belief anymore than you cherry picked your link to support yours. In fact I'd disagree its cherry picking. Flip to MVC and read the first paragraph. "MVC considers 3 roles". "the model is ___", paragraph 2 = "the view represents the display of the model in the UI", paragraph 3 = "the controller takes user input, manipulates the model, and causes the view to update".

Its his opening paragraph(s), its the only time he enumerates the responsibilities of each component, and he put "manipulating the model" under controller, not under "sometimes controller". (we could email him and ask him if he meant that to imply that only the controller should have that role?)

Let's just humor my question? Let's say you write to your models in the view. What is the purpose of a controller anymore? How do you define what goes in a controller vs what does not anymore? I don't think MVC can be defined by a dependency diagram, like I said I could put my business logic in all 3 layers to intentionally make bad code, but if my dependencies are like that diagram it doesn't make it MVC, in my opinion. If I put all my view code in the controller, all my business logic in the view, and all my presentation logic in the "model" layer.... at some point you're going to call that "not MVC", lol. The question is how much code until it becomes not MVC? 1 line in the wrong place? 100 lines?


Top
 Profile  
 
 Post subject: Re: MVC in JS (ExtJS)
PostPosted: Sat Jan 15, 2011 12:23 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group