Skip to content

Commit 1a44dcf

Browse files
authored
Type mutable style and event registry builders
Summary: ## Context Style splitting builds fresh objects, while the listener registry allocates and deletes event slots. Using readonly API types for these mutable implementation objects requires unnecessary write suppressions. The listener registry is also sparse: event keys need not exist before registration. ## Changes - Derive a mutable view-style builder with a mapped type that removes readonly, keeping readonly style inputs and returned API types. - Make listener-registry slots mutable and optional while preserving readonly event argument tuples and registrations. - Remove six obsolete suppressions for readonly writes and style-builder initialization. - Preserve runtime code, null-prototype registry storage, and existing dynamic-key suppressions. Flow configurations that check React Native implementation source need `experimental.tslib_syntax=true` for signed-readonly mapped types. The preceding configuration-only change provides that opt-in for React Native's OSS validation. Changelog: [Internal] Differential Revision: D132934090 Pull Request resolved: #60144
1 parent 888cb51 commit 1a44dcf

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎packages/react-native/Libraries/StyleSheet/splitLayoutProps.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
import type {ViewStyle} from './StyleSheetTypes';
1212

13+
type MutableViewStyle = {-readonly [K in keyof ViewStyle]: ViewStyle[K]};
14+
1315
export default function splitLayoutProps(props: ?ViewStyle): {
1416
outer: ?ViewStyle,
1517
inner: ?ViewStyle,
1618
} {
17-
let outer: ?ViewStyle = null;
18-
let inner: ?ViewStyle = null;
19+
let outer: ?MutableViewStyle = null;
20+
let inner: ?MutableViewStyle = null;
1921

2022
if (props != null) {
21-
// $FlowFixMe[incompatible-exact] Will contain a subset of keys from `props`.
2223
outer = {};
23-
// $FlowFixMe[incompatible-exact] Will contain a subset of keys from `props`.
2424
inner = {};
2525

2626
for (const prop of Object.keys(props)) {
@@ -53,13 +53,11 @@ export default function splitLayoutProps(props: ?ViewStyle): {
5353
case 'rowGap':
5454
case 'columnGap':
5555
case 'gap':
56-
// $FlowFixMe[cannot-write]
5756
// $FlowFixMe[incompatible-use]
5857
// $FlowFixMe[prop-missing]
5958
outer[prop] = props[prop];
6059
break;
6160
default:
62-
// $FlowFixMe[cannot-write]
6361
// $FlowFixMe[incompatible-use]
6462
// $FlowFixMe[prop-missing]
6563
inner[prop] = props[prop];

‎packages/react-native/Libraries/vendor/emitter/EventEmitter.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ type Registry<
5050
Record<string, ReadonlyArray<UnsafeEventObject>>,
5151
>,
5252
> = {
53-
[K in keyof TEventToArgsMap]: Set<Registration<TEventToArgsMap[K]>>,
53+
-readonly [K in keyof TEventToArgsMap]?: Set<
54+
Registration<TEventToArgsMap[K]>,
55+
>,
5456
};
5557

5658
/**
@@ -147,7 +149,6 @@ export default class EventEmitter<
147149
// $FlowFixMe[incompatible-type]
148150
this.#registry = Object.create(null);
149151
} else {
150-
// $FlowFixMe[cannot-write]
151152
delete this.#registry[eventType];
152153
}
153154
}
@@ -177,7 +178,6 @@ function allocate<
177178
registry[eventType];
178179
if (registrations == null) {
179180
registrations = new Set();
180-
// $FlowFixMe[cannot-write]
181181
registry[eventType] = registrations;
182182
}
183183
return registrations;

0 commit comments

Comments
 (0)