Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Last active January 23, 2017 07:59
Show Gist options
  • Save toddzebert/faab43dd3d33e0b16836c14e65bb81da to your computer and use it in GitHub Desktop.
Save toddzebert/faab43dd3d33e0b16836c14e65bb81da to your computer and use it in GitHub Desktop.
The Model module of a simple MVC implementation, in ES6 and module pattern
/**
* Simple MVC, 2016 Todd Zebert
* Model module
*/
var simpleMVC = (function simpleMVC(simple) {
'use strict';
simple.Model = function SimpleModel(data) {
this._data = data;
this.onSet = new simple._Event(this);
};
// define getters and setters
simple.Model.prototype = {
// get just returns the value
get() {
return this._data;
},
// sets the value and notifies any even listeners
set(data) {
this._data = data;
this.onSet.notify({ data: data });
},
};
return simple;
})(simpleMVC || {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment