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