You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@SamKissee , @iMonk777 After digging this, I found that the problem happens because startObserving function is called twice(one by initializeBackgroundObservers and the other when the first listener is added). IMO, if self.hasListeners is set to YES, we should ignore duplicate operation(which means adding observers).
I heard that there is massive factoring is on the way, so I'm not sure it's ok to submit a pr(maybe maintainers have already fixed this issue?!). Instead, if you want to fix this issue, you can apply the following simple patch using patch-package or yarn patch
-(void)startObserving {
if (self.hasListeners) {
return;
}
...rest of your codes
}
Describe the bug
When attaching the background listeners, the console logs or any other action is fire 20+ times simultaneously
To Reproduce
Place useEffect with eventListener
Launch App
Go to Health and Add Data
View Response in Logs
Expected behavior
Listener should only fire once when new sample is received.
Smartphone (please complete the following information):
Additional context
Located in our app container
React.useEffect(() => { new NativeEventEmitter(NativeModules.AppleHealthKit).addListener( 'healthKit:Running:new', async () => { console.log('--> Running observer triggered'); }, ); });
Data received from logs
LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered LOG --> Running observer triggered
The text was updated successfully, but these errors were encountered: