@frontegg/ionic-capacitor 1.0.0-alpha.0 → 1.0.0-alpha.2
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.frontegg.ionic;
|
|
2
|
+
|
|
3
|
+
import java.util.Timer;
|
|
4
|
+
import java.util.TimerTask;
|
|
5
|
+
|
|
6
|
+
public class Debouncer {
|
|
7
|
+
private final long delayMillis;
|
|
8
|
+
private Timer timer = new Timer();
|
|
9
|
+
private TimerTask task;
|
|
10
|
+
|
|
11
|
+
public Debouncer(long delayMillis) {
|
|
12
|
+
this.delayMillis = delayMillis;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public void debounce(final Runnable action) {
|
|
16
|
+
if (task != null) {
|
|
17
|
+
task.cancel();
|
|
18
|
+
}
|
|
19
|
+
task = new TimerTask() {
|
|
20
|
+
@Override
|
|
21
|
+
public void run() {
|
|
22
|
+
action.run();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
timer.schedule(task, delayMillis);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -26,6 +26,7 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
26
26
|
@CapacitorPlugin(name = "FronteggNative")
|
|
27
27
|
public class FronteggNativePlugin extends Plugin {
|
|
28
28
|
private Disposable disposable = null;
|
|
29
|
+
private Debouncer debouncer = new Debouncer(50); // 200ms delay
|
|
29
30
|
|
|
30
31
|
@Override
|
|
31
32
|
public void load() {
|
|
@@ -52,8 +53,10 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
52
53
|
auth.getInitializing().getObservable(),
|
|
53
54
|
auth.getShowLoader().getObservable()
|
|
54
55
|
).subscribe(nullableObject -> {
|
|
55
|
-
sendEvent
|
|
56
|
+
debouncer.debounce(this::sendEvent);
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
sendEvent();
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
private void sendEvent() {
|
|
@@ -12,6 +12,16 @@ public class FronteggNativePlugin: CAPPlugin {
|
|
|
12
12
|
public let fronteggApp = FronteggApp.shared
|
|
13
13
|
var cancellables = Set<AnyCancellable>()
|
|
14
14
|
|
|
15
|
+
private var workItem: DispatchWorkItem?
|
|
16
|
+
private let delay: TimeInterval = 0.05 // 200ms delay
|
|
17
|
+
|
|
18
|
+
func debounce(_ action: @escaping () -> Void) {
|
|
19
|
+
workItem?.cancel()
|
|
20
|
+
let newWorkItem = DispatchWorkItem(block: action)
|
|
21
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: newWorkItem)
|
|
22
|
+
workItem = newWorkItem
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
override public func load() {
|
|
16
26
|
|
|
17
27
|
let auth = fronteggApp.auth
|
|
@@ -30,8 +40,9 @@ public class FronteggNativePlugin: CAPPlugin {
|
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
anyChange.sink(receiveValue: { () in
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
self.debounce() {
|
|
44
|
+
self.sendEvent()
|
|
45
|
+
}
|
|
35
46
|
}).store(in: &cancellables)
|
|
36
47
|
|
|
37
48
|
self.sendEvent()
|