diff options
Diffstat (limited to 'web/src/js/stores/base.es6.js')
-rw-r--r-- | web/src/js/stores/base.es6.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/web/src/js/stores/base.es6.js b/web/src/js/stores/base.es6.js new file mode 100644 index 00000000..9e9c69aa --- /dev/null +++ b/web/src/js/stores/base.es6.js @@ -0,0 +1,26 @@ +class EventEmitter { + constructor() { + this.listeners = {}; + } + emit(event) { + if (!(event in this.listeners)) { + return; + } + this.listeners[event].forEach(function(listener) { + listener(event, this); + }.bind(this)); + } + addListener(event, f) { + this.listeners[event] = this.listeners[event] || []; + this.listeners[event].push(f); + } + removeListener(event, f) { + if (!(event in this.listeners)) { + return false; + } + var index = this.listeners[event].indexOf(f); + if (index >= 0) { + this.listeners[event].splice(index, 1); + } + } +}
\ No newline at end of file |