aboutsummaryrefslogtreecommitdiff
path: root/common/observable.js
blob: 1fb0b0ae4262a8c4d9994a375d3a3e12ab31f2cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
 */