@jsenv/filesystem 4.0.10 → 4.1.0
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.
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
export const guardTooFastSecondCall = (
|
|
2
2
|
callback,
|
|
3
3
|
cooldownBetweenFileEvents = 40,
|
|
4
|
+
) => {
|
|
5
|
+
let previousCallMs
|
|
6
|
+
return (...args) => {
|
|
7
|
+
const nowMs = Date.now()
|
|
8
|
+
if (previousCallMs) {
|
|
9
|
+
const msEllapsed = nowMs - previousCallMs
|
|
10
|
+
if (msEllapsed < cooldownBetweenFileEvents) {
|
|
11
|
+
previousCallMs = null
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
previousCallMs = nowMs
|
|
16
|
+
callback(...args)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const guardTooFastSecondCallPerFile = (
|
|
21
|
+
callback,
|
|
22
|
+
cooldownBetweenFileEvents = 40,
|
|
4
23
|
) => {
|
|
5
24
|
const previousCallMsMap = new Map()
|
|
6
25
|
return (fileEvent) => {
|
|
@@ -4,7 +4,7 @@ import { urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"
|
|
|
4
4
|
|
|
5
5
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
6
6
|
import { statsToType } from "./internal/statsToType.js"
|
|
7
|
-
import {
|
|
7
|
+
import { guardTooFastSecondCallPerFile } from "./internal/guard_second_call.js"
|
|
8
8
|
import { createWatcher } from "./internal/createWatcher.js"
|
|
9
9
|
import { trackRessources } from "./internal/trackRessources.js"
|
|
10
10
|
|
|
@@ -49,13 +49,19 @@ export const registerDirectoryLifecycle = (
|
|
|
49
49
|
}
|
|
50
50
|
if (cooldownBetweenFileEvents) {
|
|
51
51
|
if (added) {
|
|
52
|
-
added =
|
|
52
|
+
added = guardTooFastSecondCallPerFile(added, cooldownBetweenFileEvents)
|
|
53
53
|
}
|
|
54
54
|
if (updated) {
|
|
55
|
-
updated =
|
|
55
|
+
updated = guardTooFastSecondCallPerFile(
|
|
56
|
+
updated,
|
|
57
|
+
cooldownBetweenFileEvents,
|
|
58
|
+
)
|
|
56
59
|
}
|
|
57
60
|
if (removed) {
|
|
58
|
-
removed =
|
|
61
|
+
removed = guardTooFastSecondCallPerFile(
|
|
62
|
+
removed,
|
|
63
|
+
cooldownBetweenFileEvents,
|
|
64
|
+
)
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
|