aboutsummaryrefslogtreecommitdiff
path: root/common/observable.js
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-08-17 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-08-17 00:00:00 +0000
commit5b7c9edbbb46074436b819435feb80ebbd9ab4ad (patch)
treecfa7ef034d99dc1957ce3b146256d766a6a8426d /common/observable.js
parent7796e55405e2c27f053122bdec25ffc06df92b4f (diff)
parent443bc095a72949adb4a007c9a19a43da7dd8843d (diff)
downloadbrowser-extension-5b7c9edbbb46074436b819435feb80ebbd9ab4ad.tar.gz
browser-extension-5b7c9edbbb46074436b819435feb80ebbd9ab4ad.zip
Merge remote-tracking branch 'origin/master' into jahoti
Diffstat (limited to 'common/observable.js')
-rw-r--r--common/observable.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/observable.js b/common/observable.js
new file mode 100644
index 0000000..1fb0b0a
--- /dev/null
+++ b/common/observable.js
@@ -0,0 +1,36 @@
+/**
+ * part of Hachette
+ * Facilitate listening to events
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+function make()
+{
+ return new Set();
+}
+
+function subscribe(observable, cb)
+{
+ observable.add(cb);
+}
+
+function unsubscribe(observable, cb)
+{
+ observable.delete(cb);
+}
+
+function broadcast(observable, event)
+{
+ for (const callback of observable)
+ callback(event);
+}
+
+const observables = {make, subscribe, unsubscribe, broadcast};
+
+/*
+ * EXPORTS_START
+ * EXPORT observables
+ * EXPORTS_END
+ */