-
Notifications
You must be signed in to change notification settings - Fork 2
/
monitor.ts
113 lines (103 loc) · 2.04 KB
/
monitor.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import send from './accumulator';
export interface MonitorProps {
/**
* The monitors (globally unique) id.
*
* @remarks
* You can group multiple monitors together by adding a "namespace" to the id.
* See {@linkcode registerGroup}.
*/
id: string,
/** The monitors human-readable name. */
name: string,
/**
* How the monitored number should be displayed – `count` displaying a simple total,
* while `rate` shows increase per second.
*
* @defaultValue `count`
*/
type?: 'count' | 'rate',
/** Unit to display next to the total. */
unit?: string,
}
/**
* Registers a monitor.
*
* @param param0 - See {@linkcode MonitorProps}.
* @example
* ```typescript
* import { registerMonitor } from '@gdgt/devtools';
*
* registerMonitor( {
* id: 'mygroup/mymonitor',
* name: 'My Monitor',
* type: 'rate',
* } );
* ```
*/
export function registerMonitor( {
id, name, type = 'count', unit = '',
}: MonitorProps ): void {
if ( __DEV_BUILD__ ) {
send( {
intent: 'register_monitor',
value: {
id,
name,
type,
unit,
},
} );
}
}
/**
* Increments a given monitor by a given value.
*
* @param id - id of the monitor to increment.
* @param amount - The amount to increment by.
*/
export function incrementMonitor( id: string, amount = 1 ): void {
if ( __DEV_BUILD__ ) {
send( {
intent: 'increment_monitor',
value: {
id,
value: amount,
},
} );
}
}
/**
* Decrements a given monitor by a given value.
*
* @param id - id of the monitor to decrement.
* @param amount - The amount to decrement by.
*/
export function decrementMonitor( id: string, amount = 1 ): void {
if ( __DEV_BUILD__ ) {
send( {
intent: 'decrement_monitor',
value: {
id,
value: amount,
},
} );
}
}
/**
* Updates a monitor to a given value.
*
* @param id - id of the monitor to update.
* @param value - The new value.
*/
export function updateMonitor( id: string, value: number ): void {
if ( __DEV_BUILD__ ) {
send( {
intent: 'update_monitor',
value: {
id,
value,
},
} );
}
}