Created
August 11, 2012 16:25
-
-
Save darrenderidder/3325582 to your computer and use it in GitHub Desktop.
simple mvc example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Model = {}; | |
var View = {}; | |
var Controller = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Model = { | |
counter: 0 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var View = { | |
update: function(model) { | |
console.log(JSON.stringify(model)); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Controller = { | |
model: Model, | |
view: View, | |
count: function () { | |
this.model.counter++; | |
this.view.update(this.model); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller.count(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Model = { | |
counter: 0 | |
}; | |
var View = { | |
update: function(model) { | |
console.log(JSON.stringify(model)); | |
} | |
}; | |
var Controller = { | |
model: Model, | |
view: View, | |
count: function () { | |
this.model.counter++; | |
this.view.update(this.model); | |
} | |
}; | |
Controller.count(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller.count().count().count(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Controller = { | |
model: Model, | |
view: View, | |
count: function () { | |
this.model.counter++; | |
this.view.update(this.model); | |
return this; | |
} | |
}; | |
Controller.count().count().count(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var subscribers = [View]; | |
function publish(info) { | |
for (i in subscribers) { | |
subscribers[i].update(info); | |
} | |
}; | |
var Model = { | |
counter: 0, | |
incr: function () { | |
this.counter++; | |
publish(this); | |
} | |
}; | |
var View = { | |
update: function(model) { | |
console.log(JSON.stringify(model)); | |
} | |
}; | |
var Controller = { | |
model: Model, | |
count: function () { | |
this.model.incr(); | |
return this; | |
} | |
}; | |
Controller.count().count().count(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment