model view controller - Is this MVC in javascript? -



model view controller - Is this MVC in javascript? -

despite have been using mvc in php many times, found out quite different in javascript. i'm reading mvc in javascript on web, many of them have different implementation. came simple mvc, think not correct. acceptable or wrong?

var appview = view.extend({ init: function() { // hear model changes this.listen("counterchanged", $.proxy( this.updatecounter, )); // assign click event; phone call controller method this.container.find("#increase").click( this.callback( this.controller, "increase" )); this.container.find("#decrease").click( this.callback( this.controller, "decrease" )); }, updatecounter: function( evtdata ) { this.container.find("#counter").html( evtdata.newvalue ); } }); var appcontroller = controller.extend({ increase: function() { this.model.update("counter", this.model.get('counter') + 1 ); }, decrease: function() { this.model.update("counter", this.model.get('counter') - 1 ); } }); var appmodel = model.extend({ onupdate_counter: function( newvalue ) { this.fireevent("counterchanged",{ newvalue: newvalue }) } }); var app = {} $(document).ready(function(){ app.model = new appmodel({ counter: 0 }); app.controller = new appcontroller( app.model ); app.view = new appview("#app", app.controller ); app.model.setview( app.view ); });

html:

<div id='app'> <div id='counter'>0</div> <a id='increase'>increae</a> <a id='decrease'>decrease</a> </div>

view listens changes in model , assigns events html anchors. view calls controller when anchors clicked controller updates model.

this classic 1979-type mvc:

controller updates models models update views via listeners

php/rails (web request/response in general) different type of mvc (constricted request/response nature of web):

controllers update models controllers take info models , send views

in both types, view events trigger controller actions.

javascript model-view-controller design-patterns

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -