Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated "removeEventListener" syntax #2369

Closed
wants to merge 1 commit into from

Conversation

adrienharnay
Copy link

This syntax has been deprecated for over a year now. This PR addresses this.

@adrienharnay adrienharnay requested a review from a team as a code owner November 9, 2022 14:01
@Titozzz
Copy link

Titozzz commented Nov 9, 2022

Fixes #2142

}
};
AppState.addEventListener("change", resumeListener);
localAppStateListener = AppState.addEventListener("change", resumeListener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this line. Basically token (aka localAppStateListener) from adding listener, as later on passed to scope of resumeListener right to remove it?

If so Im not sure I understand what line 216 is doing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you for your answer. What I wanted to do:

  • initialize localAppStateListener with the appStateListener parameter l.216
  • assign it the return of addEventListener l.228
  • in the event listener, access localAppStateListener which will hold the return from addEventListener

I agree that initializing localAppStateListener might be pointless. Do you want me to make this change or did you have something else in mind?

@jbaudanza
Copy link

jbaudanza commented Dec 1, 2022

The AppState.removeEventListener function has been removed from React Native 0.70, so this warning is now an error:

c.AppState.removeEventListener is not a function. (In 'c.AppState.removeEventListener("change",t)', 'c.AppState.removeEventListener' is undefined)

Copy link
Contributor

@trcoffman trcoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon reading this PR, I authored #2385 which I think is a cleaner fix. There's no reason to introduce a 3rd argument, as the only purpose of the argument is to (a) determine whether or not we have already established a resumeListener, and (b) to remove the listener at the appropriate time. When the function recurses, it only needs the subscription, not the closure itself, so rather than introduce another argument, we just change what the argument is. This PR can be closed and replaced by #2385.

@Titozzz
Copy link

Titozzz commented Dec 8, 2022

@thewulf7 Gentle nudge, feel free to merge #2385 and close this one if the syntax seems clearer to you

@thewulf7
Copy link
Member

Merged #2385.Closing this

@thewulf7 thewulf7 closed this Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants