Project

General

Profile

Download (565 Bytes) Statistics
| Branch: | Tag: | Revision:

haketilo / common / observable.js @ d42dadca

1
/**
2
 * part of Hachette
3
 * Facilitate listening to events
4
 *
5
 * Copyright (C) 2021 Wojtek Kosior
6
 * Redistribution terms are gathered in the `copyright' file.
7
 */
8

    
9
function make()
10
{
11
    return new Set();
12
}
13

    
14
function subscribe(observable, cb)
15
{
16
    observable.add(cb);
17
}
18

    
19
function unsubscribe(observable, cb)
20
{
21
    observable.delete(cb);
22
}
23

    
24
function broadcast(observable, event)
25
{
26
    for (const callback of observable)
27
	callback(event);
28
}
29

    
30
const observables = {make, subscribe, unsubscribe, broadcast};
31

    
32
/*
33
 * EXPORTS_START
34
 * EXPORT observables
35
 * EXPORTS_END
36
 */
(6-6/11)