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

Return unsubscribe function from each event handler #35

Closed
pkhien95 opened this issue Sep 10, 2021 · 1 comment
Closed

Return unsubscribe function from each event handler #35

pkhien95 opened this issue Sep 10, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@pkhien95
Copy link
Contributor

Each event handler should return an unsubscribe function so that client can handle it correctly, especially in React.
For example:

const unsubscribe = messaging.onMessage(function () {
        fetchInboxCount()
})

// Unsubscribe when that screen is not rendered anymore:
unsubscribe()
@pkhien95 pkhien95 added the enhancement New feature or request label Sep 10, 2021
@tahpot
Copy link
Member

tahpot commented Sep 28, 2021

This is now implemented:

const listener = function() {
 // do something
}
const handler = messaging.onMessage(listener)
handler.removeListener('newMessage', listener)

@tahpot tahpot closed this as completed Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants