@office-iss/react-native-win32 0.69.0 → 0.70.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/.eslintrc.js +0 -1
  2. package/.flowconfig +5 -1
  3. package/CHANGELOG.json +194 -32
  4. package/CHANGELOG.md +79 -19
  5. package/IntegrationTests/AsyncStorageTest.js +20 -4
  6. package/IntegrationTests/BUCK +2 -2
  7. package/IntegrationTests/LayoutEventsTest.js +4 -1
  8. package/IntegrationTests/{launchWebSocketServer.command → launchWebSocketServer.sh} +3 -9
  9. package/Libraries/Alert/Alert.js +18 -4
  10. package/Libraries/Alert/Alert.win32.js +2 -0
  11. package/Libraries/Alert/NativeAlertManager.js +1 -0
  12. package/Libraries/Animated/Animated.js +2 -2
  13. package/Libraries/Animated/AnimatedEvent.js +7 -4
  14. package/Libraries/Animated/AnimatedImplementation.js +17 -3
  15. package/Libraries/Animated/AnimatedMock.js +7 -2
  16. package/Libraries/Animated/NativeAnimatedHelper.js +220 -95
  17. package/Libraries/Animated/NativeAnimatedModule.js +3 -0
  18. package/Libraries/Animated/NativeAnimatedTurboModule.js +3 -0
  19. package/Libraries/Animated/animations/SpringAnimation.js +3 -3
  20. package/Libraries/Animated/animations/TimingAnimation.js +3 -3
  21. package/Libraries/Animated/createAnimatedComponent.js +8 -1
  22. package/Libraries/Animated/nodes/AnimatedAddition.js +3 -1
  23. package/Libraries/Animated/nodes/AnimatedColor.js +50 -29
  24. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +3 -1
  25. package/Libraries/Animated/nodes/AnimatedDivision.js +3 -1
  26. package/Libraries/Animated/nodes/AnimatedInterpolation.js +22 -21
  27. package/Libraries/Animated/nodes/AnimatedModulo.js +3 -1
  28. package/Libraries/Animated/nodes/AnimatedMultiplication.js +3 -2
  29. package/Libraries/Animated/nodes/AnimatedProps.js +20 -12
  30. package/Libraries/Animated/nodes/AnimatedStyle.js +19 -16
  31. package/Libraries/Animated/nodes/AnimatedSubtraction.js +3 -1
  32. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -5
  33. package/Libraries/Animated/nodes/AnimatedValue.js +14 -5
  34. package/Libraries/Animated/nodes/AnimatedValueXY.js +28 -1
  35. package/Libraries/Animated/useAnimatedProps.js +1 -0
  36. package/Libraries/AppState/AppState.js +0 -32
  37. package/Libraries/BatchedBridge/MessageQueue.js +21 -15
  38. package/Libraries/BatchedBridge/NativeModules.js +3 -4
  39. package/Libraries/Blob/FileReader.js +0 -6
  40. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +0 -20
  41. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +0 -20
  42. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +4 -0
  43. package/Libraries/Components/Keyboard/Keyboard.js +0 -11
  44. package/Libraries/Components/Pressable/Pressable.js +2 -0
  45. package/Libraries/Components/Pressable/Pressable.win32.js +2 -0
  46. package/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +1 -3
  47. package/Libraries/Components/SafeAreaView/SafeAreaView.js +3 -30
  48. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +4 -32
  49. package/Libraries/Components/ScrollView/ScrollView.js +13 -11
  50. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +5 -3
  51. package/Libraries/Components/StatusBar/StatusBar.js +10 -7
  52. package/Libraries/Components/TextInput/InputAccessoryView.js +14 -13
  53. package/Libraries/Components/TextInput/TextInput.js +12 -2
  54. package/Libraries/Components/Touchable/PooledClass.js +16 -4
  55. package/Libraries/Components/Touchable/Touchable.js +50 -1
  56. package/Libraries/Components/Touchable/Touchable.win32.js +972 -0
  57. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +6 -2
  58. package/Libraries/Components/View/ReactNativeStyleAttributes.js +0 -7
  59. package/Libraries/Components/View/ViewPropTypes.js +3 -8
  60. package/Libraries/Components/View/ViewPropTypes.win32.js +3 -8
  61. package/Libraries/Core/ExceptionsManager.js +2 -0
  62. package/Libraries/Core/ReactNativeVersion.js +2 -2
  63. package/Libraries/Core/Timers/JSTimers.js +2 -2
  64. package/Libraries/Core/polyfillPromise.js +0 -32
  65. package/Libraries/Core/setUpBatchedBridge.js +5 -1
  66. package/Libraries/Core/setUpPerformance.js +1 -1
  67. package/Libraries/EventEmitter/NativeEventEmitter.js +0 -13
  68. package/Libraries/Image/AssetSourceResolver.js +2 -2
  69. package/Libraries/Image/Image.android.js +5 -3
  70. package/Libraries/Image/Image.ios.js +6 -3
  71. package/Libraries/Image/Image.win32.js +6 -3
  72. package/Libraries/Image/ImageSource.js +7 -5
  73. package/Libraries/Inspector/ElementBox.js +2 -2
  74. package/Libraries/Inspector/NetworkOverlay.js +13 -8
  75. package/Libraries/Interaction/PanResponder.js +16 -14
  76. package/Libraries/Linking/Linking.js +0 -11
  77. package/Libraries/Lists/FlatList.js +3 -2
  78. package/Libraries/Lists/SectionList.js +2 -0
  79. package/Libraries/Lists/ViewabilityHelper.js +7 -3
  80. package/Libraries/Lists/VirtualizeUtils.js +33 -20
  81. package/Libraries/Lists/VirtualizedList.js +93 -47
  82. package/Libraries/Lists/VirtualizedListContext.js +1 -0
  83. package/Libraries/Lists/VirtualizedSectionList.js +14 -9
  84. package/Libraries/Lists/__tests__/VirtualizeUtils-test.js +19 -18
  85. package/Libraries/Lists/__tests__/VirtualizedList-test.js +10 -6
  86. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  87. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  88. package/Libraries/LogBox/LogBox.js +3 -1
  89. package/Libraries/LogBox/UI/AnsiHighlight.js +2 -0
  90. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +3 -0
  91. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +0 -3
  92. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +8 -3
  93. package/Libraries/NativeComponent/BaseViewConfig.android.js +9 -18
  94. package/Libraries/NativeComponent/BaseViewConfig.ios.js +26 -12
  95. package/Libraries/NativeComponent/BaseViewConfig.win32.js +26 -12
  96. package/Libraries/Network/XMLHttpRequest.js +9 -11
  97. package/Libraries/Performance/PureComponentDebug.js +1 -0
  98. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +9 -1
  99. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +16 -0
  100. package/Libraries/Pressability/Pressability.js +26 -16
  101. package/Libraries/Pressability/Pressability.win32.js +26 -16
  102. package/Libraries/Promise.js +0 -1
  103. package/Libraries/ReactNative/AppRegistry.js +16 -13
  104. package/Libraries/ReactNative/BridgelessUIManager.js +2 -0
  105. package/Libraries/ReactNative/PaperUIManager.js +9 -9
  106. package/Libraries/ReactNative/PaperUIManager.win32.js +7 -8
  107. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +12 -0
  108. package/Libraries/ReactNative/ReactNativeRuntimeDiagnostics.js +68 -0
  109. package/Libraries/ReactNative/getNativeComponentAttributes.js +6 -7
  110. package/Libraries/ReactNative/renderApplication.js +1 -1
  111. package/Libraries/Renderer/implementations/ReactFabric-dev.js +4443 -3615
  112. package/Libraries/Renderer/implementations/ReactFabric-prod.js +1496 -1170
  113. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +1694 -1356
  114. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +4439 -3588
  115. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +1583 -1249
  116. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +1719 -1372
  117. package/Libraries/Storage/AsyncStorage.js +7 -1
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +8 -0
  119. package/Libraries/StyleSheet/flattenStyle.js +1 -1
  120. package/Libraries/StyleSheet/processTransform.js +2 -0
  121. package/Libraries/StyleSheet/splitLayoutProps.js +2 -0
  122. package/Libraries/Text/Text.js +15 -7
  123. package/Libraries/Types/CoreEventTypes.js +137 -11
  124. package/Libraries/Types/CoreEventTypes.win32.js +147 -22
  125. package/Libraries/Utilities/Dimensions.js +0 -13
  126. package/Libraries/Utilities/Dimensions.win32.js +0 -9
  127. package/Libraries/Utilities/HMRClient.js +3 -3
  128. package/Libraries/Utilities/Platform.ios.js +0 -7
  129. package/Libraries/Utilities/ReactNativeTestTools.js +3 -1
  130. package/Libraries/Utilities/codegenNativeCommands.js +11 -2
  131. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  132. package/Libraries/Utilities/stringifySafe.js +3 -1
  133. package/Libraries/Utilities/truncate.js +1 -1
  134. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +2 -2
  135. package/Libraries/Vibration/Vibration.js +1 -1
  136. package/Libraries/WebSocket/WebSocket.js +1 -0
  137. package/Libraries/vendor/emitter/EventEmitter.js +105 -12
  138. package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +73 -117
  139. package/flow/JSITimerInternalType.js +30 -0
  140. package/jest/assetFileTransformer.js +3 -2
  141. package/jest/setup.js +4 -0
  142. package/jest.config.js +0 -1
  143. package/overrides.json +23 -16
  144. package/package.json +23 -24
  145. package/rntypes/index.d.ts +0 -1
  146. package/src/rntypes/index.d.ts +0 -1
  147. package/Libraries/vendor/emitter/EventSubscription.js +0 -19
  148. package/Libraries/vendor/emitter/_EmitterSubscription.js +0 -62
  149. package/Libraries/vendor/emitter/_EventEmitter.js +0 -184
  150. package/Libraries/vendor/emitter/_EventSubscription.js +0 -45
  151. package/Libraries/vendor/emitter/_EventSubscriptionVendor.js +0 -108
  152. package/jest/preprocessor.js +0 -40
  153. package/jest/preprocessor_DO_NOT_USE.js +0 -122
  154. package/src/Libraries/Lists/__tests__/__snapshots__/VirtualizeUtils-test.js.snap +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-iss/react-native-win32",
3
- "version": "0.69.0",
3
+ "version": "0.70.0-preview.1",
4
4
  "description": "Implementation of react native on top of Office's Win32 platform.",
5
5
  "license": "MIT",
6
6
  "main": "./index.win32.js",
@@ -22,10 +22,10 @@
22
22
  "dependencies": {
23
23
  "@babel/runtime": "^7.0.0",
24
24
  "@jest/create-cache-key-function": "^27.0.1",
25
- "@react-native-community/cli": "^8.0.0",
26
- "@react-native-community/cli-platform-android": "^8.0.0",
27
- "@react-native-community/cli-platform-ios": "^8.0.0",
28
- "@react-native-windows/virtualized-list": "0.69.0",
25
+ "@react-native-community/cli": "^9.0.0-alpha.5",
26
+ "@react-native-community/cli-platform-android": "^9.0.0-alpha.5",
27
+ "@react-native-community/cli-platform-ios": "^9.0.0-alpha.5",
28
+ "@react-native-windows/virtualized-list": "0.70.0-preview.1",
29
29
  "@react-native/assets": "1.0.0",
30
30
  "@react-native/normalize-color": "2.0.0",
31
31
  "@react-native/polyfills": "2.0.0",
@@ -34,34 +34,33 @@
34
34
  "art": "^0.10.0",
35
35
  "base64-js": "^1.1.2",
36
36
  "event-target-shim": "^5.0.1",
37
- "hermes-engine": "~0.11.0",
38
37
  "invariant": "^2.2.4",
39
38
  "jsc-android": "^250230.2.1",
40
39
  "memoize-one": "^5.0.0",
41
- "metro-react-native-babel-transformer": "0.70.3",
42
- "metro-runtime": "0.70.3",
43
- "metro-source-map": "0.70.3",
40
+ "metro-react-native-babel-transformer": "0.71.3",
41
+ "metro-runtime": "0.71.3",
42
+ "metro-source-map": "0.71.3",
44
43
  "mkdirp": "^0.5.1",
45
44
  "nullthrows": "^1.1.1",
46
45
  "pretty-format": "^26.5.2",
47
46
  "promise": "^8.0.3",
48
47
  "react-clone-referenced-element": "^1.0.1",
49
48
  "react-devtools-core": "4.24.0",
50
- "react-native-codegen": "^0.69.1",
51
- "react-native-gradle-plugin": "^0.0.7",
49
+ "react-native-codegen": "^0.70.3",
50
+ "react-native-gradle-plugin": "^0.70.0",
52
51
  "react-refresh": "^0.4.0",
53
- "react-shallow-renderer": "16.14.1",
52
+ "react-shallow-renderer": "^16.15.0",
54
53
  "regenerator-runtime": "^0.13.2",
55
- "scheduler": "^0.21.0",
56
- "shelljs": "^0.8.5",
54
+ "scheduler": "^0.22.0",
57
55
  "stacktrace-parser": "^0.1.3",
58
56
  "use-sync-external-store": "^1.0.0",
59
57
  "whatwg-fetch": "^3.0.0",
60
58
  "ws": "^6.1.4"
61
59
  },
62
60
  "devDependencies": {
63
- "@rnw-scripts/eslint-config": "1.1.12",
64
- "@rnw-scripts/jest-out-of-tree-snapshot-resolver": "^1.0.6",
61
+ "@rnw-scripts/eslint-config": "1.1.13",
62
+ "@rnw-scripts/jest-out-of-tree-snapshot-resolver": "^1.0.7",
63
+ "@rnw-scripts/just-task": "2.2.5",
65
64
  "@rnw-scripts/metro-dev-config": "0.0.0",
66
65
  "@rnx-kit/jest-preset": "^0.1.0",
67
66
  "@types/node": "^14.14.22",
@@ -70,26 +69,26 @@
70
69
  "@types/react-native": "^0.66.17",
71
70
  "babel-eslint": "^10.1.0",
72
71
  "eslint": "^7.32.0",
73
- "flow-bin": "^0.176.3",
72
+ "flow-bin": "^0.182.0",
74
73
  "jscodeshift": "^0.13.1",
75
74
  "just-scripts": "^1.3.3",
76
75
  "prettier": "^2.4.1",
77
- "react": "18.0.0",
78
- "react-native": "^0.69.0",
79
- "react-native-platform-override": "^1.6.11",
76
+ "react": "18.1.0",
77
+ "react-native": "0.70.0-rc.1",
78
+ "react-native-platform-override": "^1.6.13",
80
79
  "react-shallow-renderer": "16.14.1",
81
80
  "typescript": "^4.4.4"
82
81
  },
83
82
  "peerDependencies": {
84
- "react": "18.0.0",
85
- "react-native": "^0.69.0"
83
+ "react": "18.1.0",
84
+ "react-native": "0.70.0-rc.1"
86
85
  },
87
86
  "beachball": {
88
- "defaultNpmTag": "latest",
87
+ "defaultNpmTag": "preview",
89
88
  "disallowedChangeTypes": [
90
89
  "major",
91
90
  "minor",
92
- "prerelease"
91
+ "patch"
93
92
  ]
94
93
  },
95
94
  "promoteRelease": true,
@@ -34,7 +34,6 @@
34
34
  // David Sheldrick <https://github.com/ds300>
35
35
  // Natsathorn Yuthakovit <https://github.com/natsathorn>
36
36
  // ConnectDotz <https://github.com/connectdotz>
37
- // Marcel Lasaj <https://github.com/TheWirv>
38
37
  // Alexey Molchan <https://github.com/alexeymolchan>
39
38
  // Alex Brazier <https://github.com/alexbrazier>
40
39
  // Arafat Zahan <https://github.com/kuasha420>
@@ -34,7 +34,6 @@
34
34
  // David Sheldrick <https://github.com/ds300>
35
35
  // Natsathorn Yuthakovit <https://github.com/natsathorn>
36
36
  // ConnectDotz <https://github.com/connectdotz>
37
- // Marcel Lasaj <https://github.com/TheWirv>
38
37
  // Alexey Molchan <https://github.com/alexeymolchan>
39
38
  // Alex Brazier <https://github.com/alexbrazier>
40
39
  // Arafat Zahan <https://github.com/kuasha420>
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- // This exists as a separate file only to avoid circular dependencies from
14
- // using this in `_EmitterSubscription`. Combine this back into `EventEmitter`
15
- // after migration and cleanup is done.
16
-
17
- export interface EventSubscription {
18
- remove(): void;
19
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow strict
9
- */
10
-
11
- 'use strict';
12
-
13
- import type EventEmitter from './EventEmitter';
14
- import _EventSubscription from './_EventSubscription';
15
- import type EventSubscriptionVendor from './_EventSubscriptionVendor';
16
- import type {EventSubscription} from './EventSubscription';
17
-
18
- /**
19
- * EmitterSubscription represents a subscription with listener and context data.
20
- */
21
- class EmitterSubscription<EventDefinitions: {...}, K: $Keys<EventDefinitions>>
22
- extends _EventSubscription<EventDefinitions, K>
23
- implements EventSubscription
24
- {
25
- emitter: EventEmitter<EventDefinitions>;
26
- listener: ?(...$ElementType<EventDefinitions, K>) => mixed;
27
- context: ?$FlowFixMe;
28
-
29
- /**
30
- * @param {EventEmitter} emitter - The event emitter that registered this
31
- * subscription
32
- * @param {EventSubscriptionVendor} subscriber - The subscriber that controls
33
- * this subscription
34
- * @param {function} listener - Function to invoke when the specified event is
35
- * emitted
36
- * @param {*} context - Optional context object to use when invoking the
37
- * listener
38
- */
39
- constructor(
40
- emitter: EventEmitter<EventDefinitions>,
41
- subscriber: EventSubscriptionVendor<EventDefinitions>,
42
- listener: (...$ElementType<EventDefinitions, K>) => mixed,
43
- context: ?$FlowFixMe,
44
- ) {
45
- super(subscriber);
46
- this.emitter = emitter;
47
- this.listener = listener;
48
- this.context = context;
49
- }
50
-
51
- /**
52
- * Removes this subscription from the emitter that registered it.
53
- * Note: we're overriding the `remove()` method of _EventSubscription here
54
- * but deliberately not calling `super.remove()` as the responsibility
55
- * for removing the subscription lies with the EventEmitter.
56
- */
57
- remove(): void {
58
- this.emitter.__removeSubscription(this);
59
- }
60
- }
61
-
62
- module.exports = EmitterSubscription;
@@ -1,184 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow strict
9
- * @typecheck
10
- */
11
-
12
- const invariant = require('invariant');
13
-
14
- import EmitterSubscription from './_EmitterSubscription';
15
- import type {EventSubscription} from './EventSubscription';
16
- import EventSubscriptionVendor from './_EventSubscriptionVendor';
17
-
18
- const sparseFilterPredicate = () => true;
19
-
20
- /**
21
- * @class EventEmitter
22
- * @description
23
- * An EventEmitter is responsible for managing a set of listeners and publishing
24
- * events to them when it is told that such events happened. In addition to the
25
- * data for the given event it also sends a event control object which allows
26
- * the listeners/handlers to prevent the default behavior of the given event.
27
- *
28
- * The emitter is designed to be generic enough to support all the different
29
- * contexts in which one might want to emit events. It is a simple multicast
30
- * mechanism on top of which extra functionality can be composed. For example, a
31
- * more advanced emitter may use an EventHolder and EventFactory.
32
- */
33
- class EventEmitter<EventDefinitions: {...}> {
34
- _subscriber: EventSubscriptionVendor<EventDefinitions> =
35
- new EventSubscriptionVendor<EventDefinitions>();
36
-
37
- /**
38
- * @constructor
39
- */
40
- constructor(subscriber: ?EventSubscriptionVendor<EventDefinitions>) {
41
- if (subscriber != null) {
42
- console.warn('EventEmitter(...): Constructor argument is deprecated.');
43
- this._subscriber = subscriber;
44
- }
45
- }
46
-
47
- /**
48
- * Adds a listener to be invoked when events of the specified type are
49
- * emitted. An optional calling context may be provided. The data arguments
50
- * emitted will be passed to the listener function.
51
- *
52
- * @param {string} eventType - Name of the event to listen to
53
- * @param {function} listener - Function to invoke when the specified event is
54
- * emitted
55
- * @param {*} context - Optional context object to use when invoking the
56
- * listener
57
- */
58
- addListener<K: $Keys<EventDefinitions>>(
59
- eventType: K,
60
- // FIXME: listeners should return void instead of mixed to prevent issues
61
- listener: (...$ElementType<EventDefinitions, K>) => mixed,
62
- context: $FlowFixMe,
63
- ): EventSubscription {
64
- return (this._subscriber.addSubscription(
65
- eventType,
66
- new EmitterSubscription(this, this._subscriber, listener, context),
67
- ): $FlowFixMe);
68
- }
69
-
70
- /**
71
- * Removes all of the registered listeners, including those registered as
72
- * listener maps.
73
- *
74
- * @param {?string} eventType - Optional name of the event whose registered
75
- * listeners to remove
76
- */
77
- removeAllListeners<K: $Keys<EventDefinitions>>(eventType: ?K): void {
78
- this._subscriber.removeAllSubscriptions(eventType);
79
- }
80
-
81
- /**
82
- * @deprecated Use `remove` on the EventSubscription from `addListener`.
83
- */
84
- removeSubscription<K: $Keys<EventDefinitions>>(
85
- subscription: EmitterSubscription<EventDefinitions, K>,
86
- ): void {
87
- console.warn(
88
- 'EventEmitter.removeSubscription(...): Method has been deprecated. ' +
89
- 'Please instead use `remove()` on the subscription itself.',
90
- );
91
- this.__removeSubscription(subscription);
92
- }
93
-
94
- /**
95
- * Called by `EmitterSubscription` to bypass the above deprecation warning.
96
- */
97
- __removeSubscription<K: $Keys<EventDefinitions>>(
98
- subscription: EmitterSubscription<EventDefinitions, K>,
99
- ): void {
100
- invariant(
101
- subscription.emitter === this,
102
- 'Subscription does not belong to this emitter.',
103
- );
104
- this._subscriber.removeSubscription(subscription);
105
- }
106
-
107
- /**
108
- * Returns the number of listeners that are currently registered for the given
109
- * event.
110
- *
111
- * @param {string} eventType - Name of the event to query
112
- * @returns {number}
113
- */
114
- listenerCount<K: $Keys<EventDefinitions>>(eventType: K): number {
115
- const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
116
- return subscriptions
117
- ? // We filter out missing entries because the array is sparse.
118
- // "callbackfn is called only for elements of the array which actually
119
- // exist; it is not called for missing elements of the array."
120
- // https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.filter
121
- subscriptions.filter(sparseFilterPredicate).length
122
- : 0;
123
- }
124
-
125
- /**
126
- * Emits an event of the given type with the given data. All handlers of that
127
- * particular type will be notified.
128
- *
129
- * @param {string} eventType - Name of the event to emit
130
- * @param {...*} Arbitrary arguments to be passed to each registered listener
131
- *
132
- * @example
133
- * emitter.addListener('someEvent', function(message) {
134
- * console.log(message);
135
- * });
136
- *
137
- * emitter.emit('someEvent', 'abc'); // logs 'abc'
138
- */
139
- emit<K: $Keys<EventDefinitions>>(
140
- eventType: K,
141
- ...args: $ElementType<EventDefinitions, K>
142
- ): void {
143
- const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
144
- if (subscriptions) {
145
- for (let i = 0, l = subscriptions.length; i < l; i++) {
146
- const subscription = subscriptions[i];
147
-
148
- // The subscription may have been removed during this event loop.
149
- if (subscription && subscription.listener) {
150
- subscription.listener.apply(subscription.context, args);
151
- }
152
- }
153
- }
154
- }
155
-
156
- /**
157
- * @deprecated Use `remove` on the EventSubscription from `addListener`.
158
- */
159
- removeListener<K: $Keys<EventDefinitions>>(
160
- eventType: K,
161
- // FIXME: listeners should return void instead of mixed to prevent issues
162
- listener: (...$ElementType<EventDefinitions, K>) => mixed,
163
- ): void {
164
- console.warn(
165
- `EventEmitter.removeListener('${eventType}', ...): Method has been ` +
166
- 'deprecated. Please instead use `remove()` on the subscription ' +
167
- 'returned by `EventEmitter.addListener`.',
168
- );
169
- const subscriptions = this._subscriber.getSubscriptionsForType(eventType);
170
- if (subscriptions) {
171
- for (let i = 0, l = subscriptions.length; i < l; i++) {
172
- const subscription = subscriptions[i];
173
-
174
- // The subscription may have been removed during this event loop.
175
- // its listener matches the listener in method parameters
176
- if (subscription && subscription.listener === listener) {
177
- subscription.remove();
178
- }
179
- }
180
- }
181
- }
182
- }
183
-
184
- module.exports = EventEmitter;
@@ -1,45 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow strict
9
- */
10
-
11
- 'use strict';
12
-
13
- import type {EventSubscription} from './EventSubscription';
14
- import type EventSubscriptionVendor from './_EventSubscriptionVendor';
15
-
16
- /**
17
- * EventSubscription represents a subscription to a particular event. It can
18
- * remove its own subscription.
19
- */
20
- class _EventSubscription<EventDefinitions: {...}, K: $Keys<EventDefinitions>>
21
- implements EventSubscription
22
- {
23
- eventType: K;
24
- key: number;
25
- subscriber: EventSubscriptionVendor<EventDefinitions>;
26
- listener: ?(...$ElementType<EventDefinitions, K>) => mixed;
27
- context: ?$FlowFixMe;
28
-
29
- /**
30
- * @param {EventSubscriptionVendor} subscriber the subscriber that controls
31
- * this subscription.
32
- */
33
- constructor(subscriber: EventSubscriptionVendor<EventDefinitions>) {
34
- this.subscriber = subscriber;
35
- }
36
-
37
- /**
38
- * Removes this subscription from the subscriber that controls it.
39
- */
40
- remove(): void {
41
- this.subscriber.removeSubscription(this);
42
- }
43
- }
44
-
45
- module.exports = _EventSubscription;
@@ -1,108 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow strict
9
- */
10
-
11
- 'use strict';
12
-
13
- const invariant = require('invariant');
14
-
15
- import type EventSubscription from './_EventSubscription';
16
-
17
- /**
18
- * EventSubscriptionVendor stores a set of EventSubscriptions that are
19
- * subscribed to a particular event type.
20
- */
21
- class EventSubscriptionVendor<EventDefinitions: {...}> {
22
- _subscriptionsForType: {
23
- [type: $Keys<EventDefinitions>]: Array<
24
- EventSubscription<EventDefinitions, $FlowFixMe>,
25
- >,
26
- ...
27
- };
28
-
29
- constructor() {
30
- this._subscriptionsForType = {};
31
- }
32
-
33
- /**
34
- * Adds a subscription keyed by an event type.
35
- *
36
- * @param {string} eventType
37
- * @param {EventSubscription} subscription
38
- */
39
- addSubscription<K: $Keys<EventDefinitions>>(
40
- eventType: K,
41
- subscription: EventSubscription<EventDefinitions, K>,
42
- ): EventSubscription<EventDefinitions, K> {
43
- invariant(
44
- subscription.subscriber === this,
45
- 'The subscriber of the subscription is incorrectly set.',
46
- );
47
- if (!this._subscriptionsForType[eventType]) {
48
- this._subscriptionsForType[eventType] = [];
49
- }
50
- const key = this._subscriptionsForType[eventType].length;
51
- this._subscriptionsForType[eventType].push(subscription);
52
- subscription.eventType = eventType;
53
- subscription.key = key;
54
- return subscription;
55
- }
56
-
57
- /**
58
- * Removes a bulk set of the subscriptions.
59
- *
60
- * @param {?string} eventType - Optional name of the event type whose
61
- * registered subscriptions to remove, if null remove all subscriptions.
62
- */
63
- removeAllSubscriptions<K: $Keys<EventDefinitions>>(eventType: ?K): void {
64
- if (eventType == null) {
65
- this._subscriptionsForType = {};
66
- } else {
67
- delete this._subscriptionsForType[eventType];
68
- }
69
- }
70
-
71
- /**
72
- * Removes a specific subscription. Instead of calling this function, call
73
- * `subscription.remove()` directly.
74
- *
75
- * @param {object} subscription
76
- */
77
- removeSubscription<K: $Keys<EventDefinitions>>(
78
- subscription: EventSubscription<EventDefinitions, K>,
79
- ): void {
80
- const eventType = subscription.eventType;
81
- const key = subscription.key;
82
-
83
- const subscriptionsForType = this._subscriptionsForType[eventType];
84
- if (subscriptionsForType) {
85
- delete subscriptionsForType[key];
86
- }
87
- }
88
-
89
- /**
90
- * Returns the array of subscriptions that are currently registered for the
91
- * given event type.
92
- *
93
- * Note: This array can be potentially sparse as subscriptions are deleted
94
- * from it when they are removed.
95
- *
96
- * TODO: This returns a nullable array. wat?
97
- *
98
- * @param {string} eventType
99
- * @returns {?array}
100
- */
101
- getSubscriptionsForType<K: $Keys<EventDefinitions>>(
102
- eventType: K,
103
- ): ?Array<EventSubscription<EventDefinitions, K>> {
104
- return this._subscriptionsForType[eventType];
105
- }
106
- }
107
-
108
- module.exports = EventSubscriptionVendor;
@@ -1,40 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow
9
- */
10
-
11
- /* eslint-env node */
12
-
13
- 'use strict';
14
-
15
- // NOTE: Avoiding using a package like 'chalk' here, for simplicity
16
- const YELLOW = process.stderr.isTTY ? '\u001b[33m' : '';
17
- const BOLD = process.stderr.isTTY ? '\u001b[1m' : '';
18
- const RESET = process.stderr.isTTY ? '\u001b[0m' : '';
19
- const UNDERLINE = process.stderr.isTTY ? '\u001b[4m' : '';
20
-
21
- console.warn(
22
- '\n' +
23
- YELLOW +
24
- BOLD +
25
- 'react-native/jest/preprocessor.js' +
26
- RESET +
27
- YELLOW +
28
- ' is deprecated and will be removed.\n' +
29
- 'Use "preset": "react-native" in your Jest config instead.\n' +
30
- 'See ' +
31
- UNDERLINE +
32
- 'https://jestjs.io/docs/tutorial-react-native' +
33
- RESET +
34
- YELLOW +
35
- ' for more setup instructions.' +
36
- RESET +
37
- '\n',
38
- );
39
-
40
- module.exports = require('./preprocessor_DO_NOT_USE');