Skip to content

Instantly share code, notes, and snippets.

@kageurufu
Created August 22, 2017 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kageurufu/a6ac9aa49bc6dddfc5161ef21a9bfa22 to your computer and use it in GitHub Desktop.
Save kageurufu/a6ac9aa49bc6dddfc5161ef21a9bfa22 to your computer and use it in GitHub Desktop.
var Observable = (function(){
function O(initial) {
this._value = initial;
this._callbacks = [];
return this;
}
O.prototype = {
get: function() { return this.value; },
set: function(value) { this._value = value; this.triggerChange(); },
listen: function(handler) { this._callbacks.push(handler); },
triggerChange: function() {
for (var i = this._callbacks.length - 1; i >= 0; i--) {
this._callbacks[i](this._value);
}
}
}
return O;
})()
@christru
Copy link

hmmmmm I dunno bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment