Skip to content

Commit

Permalink
fix(database): support new EventEmitter.js logic of RN 0.70.0 (#6539)
Browse files Browse the repository at this point in the history
* fix(database): support the new `EventEmitter.js` logic of RN 0.70.0 (backwards compatible)

* fix(database): typo in `removeListenerRegistrations` function
  • Loading branch information
efstathiosntonas authored Sep 15, 2022
1 parent 1b3cf96 commit 3371727
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/database/lib/DatabaseSyncTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ class DatabaseSyncTree {

for (let i = 0, len = registrations.length; i < len; i++) {
const registration = registrations[i];
const subscriptions = SharedEventEmitter._subscriber.getSubscriptionsForType(registration);
let subscriptions;

// EventEmitter in react-native < 0.70 had a `_subscriber` property with a method for subscriptions by type...
if (SharedEventEmitter._subscriber) {
subscriptions = SharedEventEmitter._subscriber.getSubscriptionsForType(registration);
} else {
// ...react-native 0.70 now stores subscribers as a map of Sets by type in `_registry`
const registrySubscriptionsSet = SharedEventEmitter._registry[registration];
if (registrySubscriptionsSet) {
subscriptions = Array.from(registrySubscriptionsSet);
}
}

if (subscriptions) {
for (let j = 0, l = subscriptions.length; j < l; j++) {
Expand Down

1 comment on commit 3371727

@vercel
Copy link

@vercel vercel bot commented on 3371727 Sep 15, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.