diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-08-14 10:07:28 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-08-14 10:07:28 +0200 |
commit | 443bc095a72949adb4a007c9a19a43da7dd8843d (patch) | |
tree | 4b3e392057d8939961a3e707ae596cd85e6fa623 /common/observable.js | |
parent | ae1844f9ac935eb3c89314cd402b4ec2c3d0f537 (diff) | |
parent | 2fbab2f07d3cebde1fba0e801df4f3e9129e463b (diff) | |
download | browser-extension-443bc095a72949adb4a007c9a19a43da7dd8843d.tar.gz browser-extension-443bc095a72949adb4a007c9a19a43da7dd8843d.zip |
merge facility to install from Hydrilla
Diffstat (limited to 'common/observable.js')
-rw-r--r-- | common/observable.js | 36 |
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 + */ |