1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.listen = exports.log = void 0;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | let id = 0;
|
12 | const subscribers = [];
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const log = (type, message, data) => {
|
20 | const obj = {
|
21 | type,
|
22 | id: String(++id),
|
23 | date: new Date()
|
24 | };
|
25 | if (message) obj.message = message;
|
26 | if (data) obj.data = data;
|
27 | dispatch(obj);
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | exports.log = log;
|
37 |
|
38 | const listen = cb => {
|
39 | subscribers.push(cb);
|
40 | return () => {
|
41 | const i = subscribers.indexOf(cb);
|
42 |
|
43 | if (i !== -1) {
|
44 |
|
45 | subscribers[i] = subscribers[subscribers.length - 1];
|
46 | subscribers.pop();
|
47 | }
|
48 | };
|
49 | };
|
50 |
|
51 | exports.listen = listen;
|
52 |
|
53 | function dispatch(log) {
|
54 | for (let i = 0; i < subscribers.length; i++) {
|
55 | try {
|
56 | subscribers[i](log);
|
57 | } catch (e) {
|
58 | console.error(e);
|
59 | }
|
60 | }
|
61 | }
|
62 |
|
63 |
|
64 | if (typeof window !== "undefined") {
|
65 | window.__ledgerLogsListen = listen;
|
66 | }
|
67 |
|
\ | No newline at end of file |