Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Created January 23, 2017 08:59
Show Gist options
  • Save toddzebert/935262614f715d687f76708378a9c9a3 to your computer and use it in GitHub Desktop.
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
/**
* 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