Created
January 23, 2017 08:59
-
-
Save toddzebert/935262614f715d687f76708378a9c9a3 to your computer and use it in GitHub Desktop.
The Controller module of a simple MVC implementation, in ES6 and module pattern
This file contains 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 module | |
*/ | |
var simpleMVC = (function simpleMVC(simple) { | |
'use strict'; | |
simple.Controller = function SimpleController(model, view) { | |
this._model = model; | |
this._view = view; | |
if (this._view.hasOwnProperty('onChanged')) { | |
this._view.onChanged.attach( | |
(sender, data) => this.update(data) | |
); | |
} | |
}; | |
simple.Controller.prototype = { | |
update(data) { | |
this._model.set(data); | |
}, | |
}; | |
return simple; | |
})(simpleMVC || {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment