Last active
January 23, 2017 08:51
-
-
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
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
/** | |
* 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