plotline-engage 3.0.9 → 3.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.
Files changed (2) hide show
  1. package/index.js +15 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -8,18 +8,26 @@ import PFlatList from './PFlatList';
8
8
  class plotline {
9
9
  constructor() {
10
10
  this.throttledNotifyScroll = this.throttle(this.handleScroll, 250);
11
+ this.lastInvokeTime = 0;
12
+ this.timeoutId = null;
11
13
  }
12
14
 
13
15
  throttle(func, limit) {
14
- let inThrottle = false;
15
16
  return function () {
16
- if (!inThrottle) {
17
- func.apply(this, arguments);
18
- inThrottle = true;
19
- setTimeout(() => {
20
- inThrottle = false;
17
+ const now = Date.now();
18
+ const timeSinceLastInvoke = now - this.lastInvokeTime;
19
+
20
+ if (timeSinceLastInvoke >= limit) {
21
+ func.apply(this, arguments);
22
+ this.lastInvokeTime = now;
23
+ } else if (this.timeoutId != null) {
24
+ clearTimeout(this.timeoutId);
25
+ }
26
+
27
+ this.timeoutId = setTimeout(() => {
28
+ func.apply(this, arguments);
29
+ this.lastInvokeTime = now;
21
30
  }, limit);
22
- }
23
31
  };
24
32
  }
25
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plotline-engage",
3
- "version": "3.0.9",
3
+ "version": "3.1.0",
4
4
  "description": "React Native plugin for Plotline",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"