@deephaven/mocks 0.24.1-beta.3 → 0.25.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,6 @@
1
1
  {
2
2
  "name": "@deephaven/mocks",
3
- "version": "0.24.1-beta.3+c65f268",
3
+ "version": "0.25.0",
4
4
  "description": "Deephaven Mocks for common libraries",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,5 +17,5 @@
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
- "gitHead": "c65f268e3b426948dc3569d1c393eb18c3b14cf4"
20
+ "gitHead": "e8da34e9b99e4af6c485c4f714ae1dcd02a97e95"
21
21
  }
@@ -1,8 +1,9 @@
1
1
  // lodash debounce needs mocking: https://github.com/facebook/jest/issues/3465#issuecomment-539496798
2
2
 
3
- const debounce = jest.fn().mockImplementation((callback, delay) => {
3
+ const debounce = jest.fn((callback, delay) => {
4
4
  let timer = null;
5
5
  let pendingArgs = null;
6
+ let lastThis = this;
6
7
 
7
8
  const cancel = jest.fn(() => {
8
9
  if (timer) {
@@ -14,17 +15,18 @@ const debounce = jest.fn().mockImplementation((callback, delay) => {
14
15
 
15
16
  const flush = jest.fn(() => {
16
17
  if (timer) {
17
- callback(...pendingArgs);
18
+ callback.apply(lastThis, pendingArgs);
18
19
  cancel();
19
20
  }
20
21
  });
21
22
 
22
- const wrapped = (...args) => {
23
+ function wrapped(...args) {
23
24
  cancel();
24
25
 
26
+ lastThis = this;
25
27
  pendingArgs = args;
26
28
  timer = setTimeout(flush, wrapped.delay);
27
- };
29
+ }
28
30
 
29
31
  wrapped.cancel = cancel;
30
32
  wrapped.flush = flush;
@@ -1,52 +1,52 @@
1
- const throttle = jest
2
- .fn()
3
- .mockImplementation((callback, delay = 0, options = {}) => {
4
- const { leading = true, trailing = true } = options;
5
- let timer = null;
6
- let pendingArgs = null;
7
- let pendingCall = false;
8
-
9
- const cancel = jest.fn(() => {
10
- if (timer) {
11
- clearTimeout(timer);
12
- }
13
- timer = null;
14
- pendingArgs = null;
15
- pendingCall = false;
16
- });
17
-
18
- const flush = jest.fn(() => {
19
- if (timer && trailing && pendingCall) {
20
- callback(...pendingArgs);
21
- }
22
- cancel();
23
- });
24
-
25
- const throttled = (...args) => {
26
- // Calling throttled function during the delay period
27
- if (timer) {
28
- pendingCall = true;
29
- pendingArgs = args;
30
- return;
31
- }
32
-
33
- // Called outside of a throttle delay
34
- if (leading) {
35
- pendingCall = false;
36
- callback(...args);
37
- } else {
38
- pendingCall = true;
39
- }
1
+ const throttle = jest.fn((callback, delay = 0, options = {}) => {
2
+ const { leading = true, trailing = true } = options;
3
+ let timer = null;
4
+ let pendingArgs = null;
5
+ let pendingCall = false;
6
+ let lastThis = this;
7
+
8
+ const cancel = jest.fn(() => {
9
+ if (timer) {
10
+ clearTimeout(timer);
11
+ }
12
+ timer = null;
13
+ pendingArgs = null;
14
+ pendingCall = false;
15
+ });
16
+
17
+ const flush = jest.fn(() => {
18
+ if (timer && trailing && pendingCall) {
19
+ callback.apply(lastThis, pendingArgs);
20
+ }
21
+ cancel();
22
+ });
40
23
 
24
+ function throttled(...args) {
25
+ lastThis = this;
26
+ // Calling throttled function during the delay period
27
+ if (timer) {
28
+ pendingCall = true;
41
29
  pendingArgs = args;
42
- timer = setTimeout(flush, throttled.delay);
43
- };
30
+ return;
31
+ }
44
32
 
45
- throttled.cancel = cancel;
46
- throttled.flush = flush;
47
- throttled.delay = delay;
33
+ // Called outside of a throttle delay
34
+ if (leading) {
35
+ pendingCall = false;
36
+ callback(...args);
37
+ } else {
38
+ pendingCall = true;
39
+ }
48
40
 
49
- return throttled;
50
- });
41
+ pendingArgs = args;
42
+ timer = setTimeout(flush, throttled.delay);
43
+ }
44
+
45
+ throttled.cancel = cancel;
46
+ throttled.flush = flush;
47
+ throttled.delay = delay;
48
+
49
+ return throttled;
50
+ });
51
51
 
52
52
  export default throttle;