Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Last active January 23, 2017 08:51
Show Gist options
  • Save toddzebert/f64660d9bdf26cccb60705cf1d4a70a2 to your computer and use it in GitHub Desktop.
Save toddzebert/f64660d9bdf26cccb60705cf1d4a70a2 to your computer and use it in GitHub Desktop.
The OneWayView module of a simple MVC implementation, in ES6 and module pattern
/**
* A 1-way View Module
*/
var simpleMVC = (function simpleMVC(simple) {
'use strict';
simple.OneWayView = function simpleOneWayView(model, selector) {
this._model = model;
this._selector = selector;
// since not a 2-way, don't need to set this.onChanged
// attach model listeners
this._model.onSet.attach(
() => this.show()
);
};
simple.OneWayView.prototype = {
show() {
this._selector.innerHTML = this._model.get();
},
};
return simple;
})(simpleMVC || {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment