aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/stores/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/stores/base.js')
-rw-r--r--web/src/js/stores/base.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/web/src/js/stores/base.js b/web/src/js/stores/base.js
new file mode 100644
index 00000000..55808deb
--- /dev/null
+++ b/web/src/js/stores/base.js
@@ -0,0 +1,24 @@
+function EventEmitter() {"use strict";
+ this.listeners = {};
+ }
+ EventEmitter.prototype.emit=function(event) {"use strict";
+ if (!(event in this.listeners)) {
+ return;
+ }
+ this.listeners[event].forEach(function(listener) {
+ listener.apply(this, arguments);
+ }.bind(this));
+ };
+ EventEmitter.prototype.addListener=function(event, f) {"use strict";
+ this.listeners[event] = this.listeners[event] || [];
+ this.listeners[event].push(f);
+ };
+ EventEmitter.prototype.removeListener=function(event, f) {"use strict";
+ if (!(event in this.listeners)) {
+ return false;
+ }
+ var index = this.listeners[event].indexOf(f);
+ if (index >= 0) {
+ this.listeners[event].splice(index, 1);
+ }
+ };