Summary:
Rewrites `EventEmitter` as a simple, type-safe abstraction with a minimal interface.
The public interface of `EventEmitter` is unchanged. This rewrite was made possible only after deprecating and removing public methods that imposed restrictions on implementation details (e.g. deleting `removeListener`).
However, this includes a subtle breaking change that makes it behave the same as `EventEmitter` in Node.js and `EventTarget` in the DOM. The set of listeners being notified by `emit` will no longer be influenced by changes made during the course of notifying the existing listeners.
Changelog:
[General][Changed] - `EventEmitter#emit` now freezes the set of listeners before iterating over them, meaning listeners that are added or removed will not affect that iteration.
Reviewed By: javache
Differential Revision: D22153962
fbshipit-source-id: 81b87113590dee0296eff61374bf732171855453
Summary:
Deletes `EventEmitter#removeSubscription`, which has been deprecated since D27704279 (cb6cbd12f8).
Relatedly, the `removeListener` family of methods (which were deprecated ad the same time) were recently removed by D35549719 (2596b2f695).
Changelog:
[General][Removed] - Removed `EventEmitter.prototype.removeSubscription` method.
Reviewed By: christophpurrer
Differential Revision: D36171048
fbshipit-source-id: 2409d235d43049cddfe0a54bcc60e1f47d4185c5
Summary:
Remove old deprecated modules that cause annoying warnings. This can be a breaking change for some third-party modules.
## Changelog
[General] [Removed] - Remove deprecated removeListener methods
Pull Request resolved: https://github.com/facebook/react-native/pull/33580
Test Plan: See `flow-check` and `build-arvr-js-flow` succeed in Sandcastle.
Reviewed By: cortinico
Differential Revision: D35549719
Pulled By: yungsters
fbshipit-source-id: 0495e36de19db434362d5de56463d9c1ad6edd73
Summary:
Changelog: [Internal]
Fixes some files to use the preferred `import type {Foo}` syntax instead of `import {type Foo}`.
Reviewed By: rh389
Differential Revision: D34001108
fbshipit-source-id: 64675fefa71b6832118eabc60c825c65b87514d9
Summary:
Ignores the `Libraries/Renderer/` directory of files which are synchronized from React (and should not be modified).
Also, formats some EventEmitter modules that for some reason were missed when I upgraded to Prettier v2.x.
## Changelog
[Internal]
Pull Request resolved: https://github.com/facebook/react-native/pull/32524
Test Plan:
```
yarn run format-check
```
Reviewed By: javache
Differential Revision: D32129837
Pulled By: yungsters
fbshipit-source-id: 1cb42cec210508db499850e13f77beefdb35eb25
Summary:
Deprecates `EventEmitter#removeSubscription`. This required temporarily introducing a new `__removeSubscription` method that is only invoked by `EmitterSubscription`. This is necessary so that we do not completely break usages of `EventEmitter` that are supplying constructor arguments (which is also deprecated, but still supported until the next release).
Calling this method will now cause a warning to appear with instructions to instead invoke `remove()` on the subscription itself.
Lastly, changed `console.error` deprecation notice to instead use `console.warn`. This is in line with the principle that errors are "broken today" and warnings will be "broken tomorrow".
Changelog:
[General][Deprecated] - `EventEmitter#removeSubscription` is now deprecated.
Reviewed By: rubennorte
Differential Revision: D27704279
fbshipit-source-id: 581f5b2ab46b1bcfc1d20898b3d3392988dccbd5
Summary:
Cleans up some minor redundant internal types in `_EventEmitter.js`.
Changelog:
[Internal]
Reviewed By: rubennorte
Differential Revision: D27712301
fbshipit-source-id: e6affcb7948e0f47a1775b74b12f59ec2a6abddb
Summary:
Deprecates the constructor argument to `EventEmitter`.
It was only ever used by React Native to instantiate a `NativeEventEmitter` with the same "vendor" as `RCTDeviceEventEmitter`, which was a gross violation of encapsulation that led to an overcomplicated implementation of `EventEmitter`. I am now untangling that mess.
Changelog:
[General][Deprecated] - It is now deprecated to pass a constructor argument to `EventEmitter(...)`.
Reviewed By: rubennorte
Differential Revision: D27704182
fbshipit-source-id: 102f26a8a9c029f0e7a1346dc2f2d9f2548d6a42
Summary:
Restore deprecated event listener removal methods in order to minimize breaking changes for the next release. The methods will work, but they will not report a warning via `console.error`.
Changelog:
[General][Added] - `EventEmitter.removeListener` now emits a deprecation notice.
[General][Added] - Restored `AppState.removeEventListener` with a deprecation notice.
[General][Added] - Restored `Keyboard.removeEventListener` with a deprecation notice.
[General][Added] - Restored `Linking.removeEventListener` with a deprecation notice.
Reviewed By: nadiia, kacieb
Differential Revision: D26589441
fbshipit-source-id: 7d89982a182cf2163136e157d4c1beee91c30393
Summary:
Simplifies `RCTDeviceEventEmitter` to simply be an `EventEmitter`.
The only thing special about it is that all native events are emitted on it and that `NativeEventEmitter` composes it.
Changelog:
[General][Removed] - Removed `RCTDeviceEventEmitter.sharedSubscribers`.
Reviewed By: RSNara
Differential Revision: D26163660
fbshipit-source-id: aedff8323d86947220fc293a74a19a3981fd875a
Summary:
Rewrites `NativeEventEmitter` to not extend `EventEmitter` and to compose `RCTDeviceEventEmitter` instead of (mis)using its exported `sharedSubscriber` property.
This makes it easier to reason about `NativeEventEmitter`. Also, the extraneous methods on `EventEmitter` are no longer inherited.
Changelog:
[General][Removed] - `NativeEventEmitter` no longer inherits from `EventEmitter`, so it no longer implements `removeListener` and `removeSubscription`. Instead, use the `remove()` method on the subscription object returned by `addListener`.
Reviewed By: rubennorte
Differential Revision: D26163562
fbshipit-source-id: c1aadb99bdefbaa36fece57ce74604e414f94d4d
Summary:
ES Modules implicitly enable strict mode. Adding the "use strict" directive is, therefore, not required.
This diff removes all "use strict" directives from ES modules.
Changelog:
[Internal]
Reviewed By: motiz88
Differential Revision: D26172715
fbshipit-source-id: 57957bcbb672c4c3e62b1db633cf425c1c9d6430
Summary:
Changes the to-be-legacy `_EventSubscription` and `_EmitterSubscription` classes to implement the event-agnostic `EventSubscription` interface.
This interface is valuable because it abstracts away the event definitions.
Changelog:
[Internal]
Reviewed By: lunaleaps
Differential Revision: D26155911
fbshipit-source-id: f94280976d4f9219f4780ac8fae0d5fbc1865386
Summary:
Adds types to Event Emitters and migrates the most relevant modules using them in `react-native`.
The most relevant file of this diff is `react-native/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js` with the Flow tests showing and testing the behavior of the new types
Changelog: [Internal] Add types for Event Emitters and subclasses
Reviewed By: motiz88
Differential Revision: D25587936
fbshipit-source-id: feeb09f9ad15d383cdd82deaaaba0d12b94e868b
Summary:
Replaces the `listeners()` method on `EventEmitter` with a `listenerCount()` method.
Changelog:
[General][Removed] - Removed `listeners()` from `DeviceEventEmitter` and `NativeEventEmitter`.
[General][Added] - Added `listenerCount()` to `DeviceEventEmitter` and `NativeEventEmitter`.
Reviewed By: cpojer
Differential Revision: D22204156
fbshipit-source-id: 15029525aeef55de9934a4f319910e666ecbe1d8
Summary:
In an effort to simplify and clean up the `EventEmitter` abstractions in React Native, this removes `once()` and `removeCurrentListener()`. Across the Facebook codebase, there were only two callers of `once()` and no callers of `removeCurrentListener()`.
The same behavior can be achieved using:
```
const subscription = emitter.addListener('event', () => {
subscription.remove();
// ...
});
```
Changelog:
[General][Removed] - Removed `once()` and `removeCurrentListener()` fom `DeviceEventEmitter` and `NativeEventEmitter`.
Reviewed By: cpojer
Differential Revision: D22196474
fbshipit-source-id: 06ced186fd812e91d5c57f6580e647c100505807
Summary:
Renames `EventSubscription.js`, `EmitterSubscription.js`, and `EventSubscriptionVendor.js` to `_EventSubscription.js`, `_EmitterSubscription.js`, and `_EventSubscriptionVendor.js`, respectively.
This is to indicate that those files are implementation details and should not be directly referenced. Instead, the `EventSubscription` type exported from `EventEmitter.js` should be used.
The remaining stragglers that are importing `_EmitterSubscription.js` and `_EventSubscriptionVendor.js` after this commit will be cleaned up when `RCTDeviceEventEmitter` is refactored.
Changelog:
[Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: cpojer
Differential Revision: D22182310
fbshipit-source-id: 82be685f231395bd7b8e9986141b5df1367bec71
Summary:
Changes `EventEmitter.js` to be Flow-typed so that it can export an interface for `EventSubscription`. In order to retain the untyped-ness of `EventEmitter.js`, I moved the entire definition into an untyped `_EventEmitter.js` file (which I hope no one will try importing from).
This new interface will be used to replace all the current type imports of `EventSubscription` and `EmitterSubscription`.
Changelog:
[Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: cpojer
Differential Revision: D22182311
fbshipit-source-id: c604a371a91963116621e89ca63f5a82167090b9
Summary:
Upgrades dependents of `EventEmitter`, `EventSubscription`, `EventSubscriptionVendor`, and `EmitterSubscription` to use `import` instead of `require`.
Changelog:
[Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: cpojer
Differential Revision: D22182312
fbshipit-source-id: e9444aa2728d89d52f577725f688871f7dbfba8a
Summary:
This gets us on the latest Prettier 2.x:
https://prettier.io/blog/2020/03/21/2.0.0.html
Notably, this adds support for TypeScript 3.8,
which introduces new syntax, such as `import type`.
Reviewed By: zertosh
Differential Revision: D20636268
fbshipit-source-id: fca5833d003804333a05ba16325bbbe0e06d6c8a
Summary:
A few recent imports have explicitly added ".js" to the end of their path. This prevents Metro from resolving platform-specific JS files, e.g. "Foo.android.js" or "Foo.windows.js" instead of "Foo.js".
React Native Windows provides its own implementation of files in a few cases where stock React Native will share them between Android and iOS. We hope to reduce/eliminate these long term, but requiring explicit ".js" files currently breaks us in a couple of places where we have custom implementations.
This change is a quick regex replace of ES6 and CommonJS imports in 'Libraries/" to eliminate ".js".
## Changelog
[General] [Fixed] - Do not explicitly include ".js" in Library imports
Pull Request resolved: https://github.com/facebook/react-native/pull/28311
Test Plan: I haven't done any manual validation of this, but `flow-check` should catch any issues with this during CI.
Reviewed By: cpojer
Differential Revision: D20486466
Pulled By: TheSavior
fbshipit-source-id: 31e1ccc307967417d7d09c34c859f0b2b69eac84
Summary:
Deletes `getObjectValues` because there are no more references to it in `react-native`.
Changelog:
[Internal]
Reviewed By: TheSavior
Differential Revision: D17884311
fbshipit-source-id: c97caeed00fe94a6cc099fba7039d9defee719dd
Summary:
Deletes `isEmpty` because there are no more references to it in `react-native`.
Changelog:
[Internal]
Reviewed By: zackargyle, fred2028
Differential Revision: D17884310
fbshipit-source-id: 0554aee4044452b6c04f638f1ad762025eecd929
Summary:
Deletes `guid` because there are no more references to it in `react-native`.
Changelog:
[Internal]
Reviewed By: zackargyle
Differential Revision: D17882369
fbshipit-source-id: c3ee6d23e5fa233a7f5d2e2c7baef005384ea5b1
Summary:
Deletes `toIterator` because there are no more call sites.
Changelog:
[Internal]
Reviewed By: TheSavior
Differential Revision: D17879834
fbshipit-source-id: 95679d7504c044d0e842bfcbdc07a8c33268f5d6
Summary:
Deletes `mixInEventEmitter` and its dependencies that are no longer being used by anything in `react-native`.
Changelog:
[Internal]
Reviewed By: TheSavior
Differential Revision: D17879835
fbshipit-source-id: 45f30d21cb01365fcfc723cf564ebb47794ea176
Summary:
Deletes the `selectionState` prop from `TextInput`.
It does not provide meaningful value over `onBlur`, `onFocus`, and `selectionState`.
Changelog:
[Breaking][TextInput] Removing `selectionState` prop, use `onBlur`, `onFocus`, and `onUpdate` instead.
Reviewed By: zackargyle, TheSavior
Differential Revision: D17879667
fbshipit-source-id: 03a4e239406932adad898d6d2a092e3bc2e6b064
Summary:
This is used by Image.android.js and needs to be flow typed to be able to have confidence in the requireNativeComponent type change
Changelog:
[Internal] Flow type vendor/core/merge.js
Reviewed By: JoshuaGross
Differential Revision: D17561195
fbshipit-source-id: 2639f2628e15b2dd5469bb2ebfe935a444025a21
Summary:
Need to add explicit type annotations in these areas to unblock types-first architecture for Flow. These are locations the codemod could not automatically handle.
I'll call out areas I need a close eye on in the comments.
Reviewed By: panagosg7
Differential Revision: D16659053
fbshipit-source-id: 167dd2abe093019b128676426374c1c62cf71e7f
Summary:
* Adds Flow types to `error-guard.js` and propagates them via the `ErrorUtils` module.
* Fixes some call sites to account for the stricter (correct) types.
Differential Revision: D16619538
fbshipit-source-id: c006ff2736ec380763956c4b89702cf44dd4deb0
Summary:
This is the same diff as D14786123 but with one of the buck targets fixed that only failed on continuous and didn't run during land time.
This moves Map/Set to fb internal. We do not need them in open source any more but we still need this in some apps at FB that use an old version of JSC.
Reviewed By: rickhanlonii
Differential Revision: D15713305
fbshipit-source-id: caec43c76a6255b2af1693c13d8dea31d7d674f5
Summary: This moves Map/Set to fb internal. We do not need them in open source any more but we still need this in some apps at FB that use an old version of JSC.
Reviewed By: TheSavior
Differential Revision: D14786123
fbshipit-source-id: 1c49b47d547ad30f2d93c00b44382cf410100b67
Summary:
The original reason for vendoring the fetch polyfill was to remove the default blob response type but this was reverted.
Here's a little history around the fetch polyfill and the blob issue:
- Original commit introducing the vendored polyfill: #19333, the goal was to fix a memory leak because our blob implementation doesn't release resources automatically. Not an ideal fix but since the issue was pretty severe and the infra for a proper fix was not in place.
- This introduced an issue when downloading images using `fetch` which was fixed by #22063 which re-added the default blob content type. However that re-introduced the original fetch memory leak.
- We have better infra now with jsi and I was able to get blob deallocation working, see #24405
Currently the vendored fetch polyfill is useless since it was changed back to the original version. We can just use the npm version again. I also updated to 3.0 which brings better spec compliance and support for cancellation via `AbortController`, https://github.com/github/fetch/releases/tag/v3.0.0.
## Changelog
[General] [Changed] - Remove vendored fetch polyfill, update to whatwg-fetch@3.0
Pull Request resolved: https://github.com/facebook/react-native/pull/24418
Differential Revision: D14932683
Pulled By: cpojer
fbshipit-source-id: 915e3d25978e8b9d7507ed807e7fba45aa88385a
Summary:
This is the next step in moving RN towards standard path-based requires. All the requires in `Libraries/vendor` have been rewritten to use relative requires. Talking to cpojer, the vendored code in RN can be modified directly.
This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.
Closes#24769.
[General] [Changed] - Migrate vendored code from Haste to path-based imports
Pull Request resolved: https://github.com/facebook/react-native/pull/24807
Differential Revision: D15316831
Pulled By: cpojer
fbshipit-source-id: 19475823ce9f506600bd09b001156e306bff4db8
Summary:
Fixes a regression in 1f8b46a2fc. The internal subscription vendor uses a sparse array to track listeners, which makes listener removal fast. When querying listeners, the sparse entries need to be removed. `Array#filter` is a built-in way to do this -> linked to the JS spec, which explains this.
[General] [Fixed] - Fixed sparse array handling in `EventEmitter#listeners()`
Pull Request resolved: https://github.com/facebook/react-native/pull/24546
Differential Revision: D15044790
Pulled By: cpojer
fbshipit-source-id: 0f1301618739357b4a0f5378b9584efe74f0f09a
Summary: Now that React Native ships with a newer version of JSC, we do not need this code to wrap `Object.freeze` any longer.
Reviewed By: mmmulani
Differential Revision: D14779239
fbshipit-source-id: 1a6e1a9c7f4312572bd08ba604fa8c9d6b1927e1