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

Snapshot the Set of listeners when dispatching a BackAndroid event #5783

Conversation

fabianeichinger
Copy link
Contributor

…while an event is dispatched

While it is guarded, a copy of the Set is created before listeners are added or removed. The event dispatch loop continues with the old Set of listeners.

This PR modifies BackAndroid to match the proposal at the end of #5781.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @foghina and @jutaz to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

var _backPressSubscriptions = new Set();

RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() {
_copySubsSetInsteadOfModify = true;
var backPressSubscriptions = _backPressSubscriptions;

Choose a reason for hiding this comment

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

no-trailing-spaces: Trailing spaces not allowed.

@ide
Copy link
Contributor

ide commented Feb 6, 2016

I think this is right. Node's event emitter snapshots the set of event handlers when the event is first fired. We should probably always copy the handler set -- the bookkeeping with the boolean is complicated.

@foghina
Copy link
Contributor

foghina commented Feb 6, 2016

Isn't it easier to just copy it every time in the listener?

@fabianeichinger
Copy link
Contributor Author

Yeah, you are right, this is too complicated for what it is doing.
I'll change it to just copy the set and update the PR.

@facebook-github-bot
Copy link
Contributor

@feichngr updated the pull request.

@fabianeichinger fabianeichinger changed the title Guard the Set of listeners in BackAndroid from modification Snapshot the Set of listeners when dispatching a BackAn Feb 6, 2016
@fabianeichinger fabianeichinger changed the title Snapshot the Set of listeners when dispatching a BackAn Snapshot the Set of listeners when dispatching a BackAndroid event Feb 6, 2016
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 6, 2016
@foghina
Copy link
Contributor

foghina commented Feb 8, 2016

Thanks for the PR!

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1101528873231987/int_phab to review.

@ghost ghost closed this in 9040315 Feb 8, 2016
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
…while an event is dispatched

While it is guarded, a copy of the Set is created before listeners are added or removed. The event dispatch loop continues with the old Set of listeners.

This PR modifies `BackAndroid` to match the proposal at the end of facebook#5781.
Closes facebook#5783

Reviewed By: svcscm

Differential Revision: D2911282

Pulled By: foghina

fb-gh-sync-id: 34964ec3414af85eb9574bbcef081238fc67ffaf
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants