@parcel/transformer-react-refresh-wrap 2.7.0 → 2.8.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.
@@ -8,13 +8,26 @@ function debounce(func, delay) {
8
8
  func.call(null, args);
9
9
  };
10
10
  } else {
11
- var timeout = undefined;
11
+ let timeout = undefined;
12
+ let lastTime = 0;
12
13
  return function (args) {
13
- clearTimeout(timeout);
14
- timeout = setTimeout(function () {
15
- timeout = undefined;
14
+ // Call immediately if last call was more than the delay ago.
15
+ // Otherwise, set a timeout. This means the first call is fast
16
+ // (for the common case of a single update), and subsequent updates
17
+ // are batched.
18
+ let now = Date.now();
19
+
20
+ if (now - lastTime > delay) {
21
+ lastTime = now;
16
22
  func.call(null, args);
17
- }, delay);
23
+ } else {
24
+ clearTimeout(timeout);
25
+ timeout = setTimeout(function () {
26
+ timeout = undefined;
27
+ lastTime = Date.now();
28
+ func.call(null, args);
29
+ }, delay);
30
+ }
18
31
  };
19
32
  }
20
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/transformer-react-refresh-wrap",
3
- "version": "2.7.0",
3
+ "version": "2.8.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,12 +17,12 @@
17
17
  "source": "src/ReactRefreshWrapTransformer.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "^2.7.0"
20
+ "parcel": "^2.8.1"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/plugin": "2.7.0",
24
- "@parcel/utils": "2.7.0",
23
+ "@parcel/plugin": "2.8.1",
24
+ "@parcel/utils": "2.8.1",
25
25
  "react-refresh": "^0.9.0"
26
26
  },
27
- "gitHead": "9e5d05586577e89991ccf90400f2c741dca11aa3"
27
+ "gitHead": "f8d3fc30ca5b33d8f8674525f2a741d662c5986a"
28
28
  }
@@ -6,13 +6,25 @@ function debounce(func, delay) {
6
6
  func.call(null, args);
7
7
  };
8
8
  } else {
9
- var timeout = undefined;
9
+ let timeout = undefined;
10
+ let lastTime = 0;
10
11
  return function (args) {
11
- clearTimeout(timeout);
12
- timeout = setTimeout(function () {
13
- timeout = undefined;
12
+ // Call immediately if last call was more than the delay ago.
13
+ // Otherwise, set a timeout. This means the first call is fast
14
+ // (for the common case of a single update), and subsequent updates
15
+ // are batched.
16
+ let now = Date.now();
17
+ if (now - lastTime > delay) {
18
+ lastTime = now;
14
19
  func.call(null, args);
15
- }, delay);
20
+ } else {
21
+ clearTimeout(timeout);
22
+ timeout = setTimeout(function () {
23
+ timeout = undefined;
24
+ lastTime = Date.now();
25
+ func.call(null, args);
26
+ }, delay);
27
+ }
16
28
  };
17
29
  }
18
30
  }