debounced 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/debounced/javascript/service.mjs +13 -17
- data/lib/debounced/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9fa1cd41e5d203718e5f338068db77acd8b07f15369c705e096f9a2108b7614
|
|
4
|
+
data.tar.gz: 544067be17e4efad251d656374b5d41a08c2c3ad627fc7f0ac75dbdf83be0c05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7965f45c4e5055cf0c0e98123c6e88b5e7f1d9ef2ac6e0ecc1a3f09e51364b6feb2d5c3f07dc294d54a6f15af717cf6b6ccb87eae090466583f07f8ff6d162cd
|
|
7
|
+
data.tar.gz: 7165afce55d82ff97a1747181bd219e63a94ac79f23d0ec3b3ffbc04b4c6ce31f83be4b1a3372dd20484bae19db00f4546e7e4bc02f162efaf5dc560c4569fae
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Each process's descriptors are debounced separately. When two processes debounced the same descriptor, the later
|
|
13
|
+
request cancelled the earlier process's callback; now each process gets its own callback, and a process's pending
|
|
14
|
+
callbacks are cancelled when it disconnects
|
|
15
|
+
|
|
16
|
+
## [2.1.0] - 2026-09-26
|
|
17
|
+
|
|
10
18
|
### Security
|
|
11
19
|
|
|
12
20
|
- Callbacks are only dispatched to public methods defined by the application, never to core Ruby methods
|
|
@@ -9,8 +9,7 @@ function log(message, ...args) {
|
|
|
9
9
|
export default class DebounceService {
|
|
10
10
|
constructor(socketDescriptor) {
|
|
11
11
|
this._socketDescriptor = socketDescriptor;
|
|
12
|
-
this._timers =
|
|
13
|
-
this._clients = new Set();
|
|
12
|
+
this._timers = new Map();
|
|
14
13
|
this.publishEvent = this.publishEvent.bind(this);
|
|
15
14
|
this.debounceEvent = this.debounceEvent.bind(this);
|
|
16
15
|
this.reset = this.reset.bind(this);
|
|
@@ -29,7 +28,8 @@ export default class DebounceService {
|
|
|
29
28
|
|
|
30
29
|
onClientDisconnected(socket) {
|
|
31
30
|
log('DebounceService client disconnected');
|
|
32
|
-
this.
|
|
31
|
+
this._timers.get(socket).forEach(timerID => clearTimeout(timerID));
|
|
32
|
+
this._timers.delete(socket);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
handleMessage(message, socket) {
|
|
@@ -50,7 +50,7 @@ export default class DebounceService {
|
|
|
50
50
|
onClientConnected(socket) {
|
|
51
51
|
log('DebounceService client connected');
|
|
52
52
|
let connectionBuffer = '';
|
|
53
|
-
this.
|
|
53
|
+
this._timers.set(socket, new Map());
|
|
54
54
|
socket.on('close', () => this.onClientDisconnected(socket));
|
|
55
55
|
socket.on('error', this.onConnectionError);
|
|
56
56
|
socket.setEncoding('utf8');
|
|
@@ -135,11 +135,6 @@ export default class DebounceService {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
publishEvent(descriptor, callback, socket) {
|
|
138
|
-
if (!this._clients.has(socket)) {
|
|
139
|
-
log(`Debounce period expired for ${descriptor} - client disconnected, dropping`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
138
|
log(`Debounce period expired for ${descriptor} - sending to client`);
|
|
144
139
|
const message = JSON.stringify({
|
|
145
140
|
type: 'publishEvent',
|
|
@@ -149,20 +144,21 @@ export default class DebounceService {
|
|
|
149
144
|
}
|
|
150
145
|
|
|
151
146
|
debounceEvent({ descriptor, timeout, callback }, socket) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
147
|
+
const timers = this._timers.get(socket);
|
|
148
|
+
clearTimeout(timers.get(descriptor));
|
|
155
149
|
|
|
156
150
|
log("Debouncing", descriptor);
|
|
157
|
-
|
|
158
|
-
delete
|
|
151
|
+
timers.set(descriptor, setTimeout(() => {
|
|
152
|
+
timers.delete(descriptor);
|
|
159
153
|
this.publishEvent(descriptor, callback, socket);
|
|
160
|
-
}, timeout * 1000);
|
|
154
|
+
}, timeout * 1000));
|
|
161
155
|
}
|
|
162
156
|
|
|
163
157
|
reset() {
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
this._timers.forEach(timers => {
|
|
159
|
+
timers.forEach(timerID => clearTimeout(timerID));
|
|
160
|
+
timers.clear();
|
|
161
|
+
});
|
|
166
162
|
}
|
|
167
163
|
|
|
168
164
|
handleError(err) {
|
data/lib/debounced/version.rb
CHANGED