Remove ReactNativePropRegistry (#12559)
This has always been an unnecessary indirection to protect opaqueness, which hasn't really worked out.
Sebastian Markbåge committed
Apr 9, 2018 at 19:02 UTC
933f882a9df728662befe558005f2ea3fe827a1d
7 files changed
+9
-95
packages/react-native-renderer/src/ReactFabric.js
-2
@@ -21,7 +21,6 @@ import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
21
import ReactNativeComponent from './ReactNativeComponent';
22
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
23
import ReactFabricRenderer from './ReactFabricRenderer';
24
-import ReactNativePropRegistry from './ReactNativePropRegistry';
24
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
25
import createReactNativeComponentClass from './createReactNativeComponentClass';
26
import {injectFindHostInstance} from './findNodeHandle';
@@ -82,7 +81,6 @@ const ReactFabric: ReactNativeType = {
81
// Used by react-native-github/Libraries/ components
82
ReactNativeBridgeEventPlugin, // requireNativeComponent
83
ReactNativeComponentTree, // ScrollResponder
85
- ReactNativePropRegistry, // flattenStyle, Stylesheet
84
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
85
},
86
};
packages/react-native-renderer/src/ReactNativeAttributePayload.js
+7
-29
@@ -11,8 +11,6 @@
11
import deepDiffer from 'deepDiffer';
12
import flattenStyle from 'flattenStyle';
13
14
-import ReactNativePropRegistry from './ReactNativePropRegistry';
15
-
14
const emptyObject = {};
15
16
/**
@@ -38,7 +36,7 @@ type AttributeConfiguration = {
36
| AttributeConfiguration /*| boolean*/,
37
};
38
41
-type NestedNode = Array<NestedNode> | Object | number;
39
+type NestedNode = Array<NestedNode> | Object;
40
41
// Tracks removed keys
42
let removedKeys = null;
@@ -54,13 +52,6 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
52
}
53
}
54
57
-function resolveObject(idOrObject: number | Object): Object {
58
- if (typeof idOrObject === 'number') {
59
- return ReactNativePropRegistry.getByID(idOrObject);
60
- }
61
- return idOrObject;
62
-}
63
-
55
function restoreDeletedValuesInNestedArray(
56
updatePayload: Object,
57
node: NestedNode,
@@ -76,7 +67,7 @@ function restoreDeletedValuesInNestedArray(
67
);
68
}
69
} else if (node && removedKeyCount > 0) {
79
- const obj = resolveObject(node);
70
+ const obj = node;
71
for (const propKey in removedKeys) {
72
if (!removedKeys[propKey]) {
73
continue;
@@ -180,12 +171,7 @@ function diffNestedProperty(
171
172
if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
173
// Both are leaves, we can diff the leaves.
183
- return diffProperties(
184
- updatePayload,
185
- resolveObject(prevProp),
186
- resolveObject(nextProp),
187
- validAttributes,
188
- );
174
+ return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
175
}
176
177
if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
@@ -204,14 +190,14 @@ function diffNestedProperty(
190
// $FlowFixMe - We know that this is always an object when the input is.
191
flattenStyle(prevProp),
192
// $FlowFixMe - We know that this isn't an array because of above flow.
207
- resolveObject(nextProp),
193
+ nextProp,
194
validAttributes,
195
);
196
}
197
198
return diffProperties(
199
updatePayload,
214
- resolveObject(prevProp),
200
+ prevProp,
201
// $FlowFixMe - We know that this is always an object when the input is.
202
flattenStyle(nextProp),
203
validAttributes,
@@ -234,11 +220,7 @@ function addNestedProperty(
220
221
if (!Array.isArray(nextProp)) {
222
// Add each property of the leaf.
237
- return addProperties(
238
- updatePayload,
239
- resolveObject(nextProp),
240
- validAttributes,
241
- );
223
+ return addProperties(updatePayload, nextProp, validAttributes);
224
}
225
226
for (let i = 0; i < nextProp.length; i++) {
@@ -268,11 +250,7 @@ function clearNestedProperty(
250
251
if (!Array.isArray(prevProp)) {
252
// Add each property of the leaf.
271
- return clearProperties(
272
- updatePayload,
273
- resolveObject(prevProp),
274
- validAttributes,
275
- );
253
+ return clearProperties(updatePayload, prevProp, validAttributes);
254
}
255
256
for (let i = 0; i < prevProp.length; i++) {
packages/react-native-renderer/src/ReactNativePropRegistry.js
deleted
-40
@@ -1,40 +0,0 @@
1
-/**
2
- * Copyright (c) 2015-present, Facebook, Inc.
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
8
- */
9
-
10
-const objects = {};
11
-let uniqueID = 1;
12
-const emptyObject = {};
13
-
14
-class ReactNativePropRegistry {
15
- static register(object: Object): number {
16
- const id = ++uniqueID;
17
- if (__DEV__) {
18
- Object.freeze(object);
19
- }
20
- objects[id] = object;
21
- return id;
22
- }
23
-
24
- static getByID(id: number): Object {
25
- if (!id) {
26
- // Used in the style={[condition && id]} pattern,
27
- // we want it to be a no-op when the value is false or null
28
- return emptyObject;
29
- }
30
-
31
- const object = objects[id];
32
- if (!object) {
33
- console.warn('Invalid style with id `' + id + '`. Skipping ...');
34
- return emptyObject;
35
- }
36
- return object;
37
- }
38
-}
39
-
40
-export default ReactNativePropRegistry;
packages/react-native-renderer/src/ReactNativeRenderer.js
-2
@@ -25,7 +25,6 @@ import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
25
import ReactNativeComponent from './ReactNativeComponent';
26
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
27
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
28
-import ReactNativePropRegistry from './ReactNativePropRegistry';
28
import {getInspectorDataForViewTag} from './ReactNativeFiberInspector';
29
import createReactNativeComponentClass from './createReactNativeComponentClass';
30
import {injectFindHostInstance} from './findNodeHandle';
@@ -101,7 +100,6 @@ const ReactNativeRenderer: ReactNativeType = {
100
// Used by react-native-github/Libraries/ components
101
ReactNativeBridgeEventPlugin, // requireNativeComponent
102
ReactNativeComponentTree, // ScrollResponder
104
- ReactNativePropRegistry, // flattenStyle, Stylesheet
103
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
104
computeComponentStackForErrorReporting,
105
},
packages/react-native-renderer/src/ReactNativeTypes.js
-1
@@ -81,7 +81,6 @@ type SecretInternalsType = {
81
): any,
82
ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin,
83
ReactNativeComponentTree: any,
84
- ReactNativePropRegistry: any,
84
// TODO (bvaughn) Decide which additional types to expose here?
85
// And how much information to fill in for the above types.
86
};
packages/react-native-renderer/src/__tests__/ReactNativeAttributePayload-test.js
+2
-3
@@ -9,7 +9,6 @@
9
'use strict';
10
11
const ReactNativeAttributePayload = require('../ReactNativeAttributePayload');
12
-const ReactNativePropRegistry = require('../ReactNativePropRegistry').default;
12
13
const diff = ReactNativeAttributePayload.diff;
14
@@ -114,9 +113,9 @@ describe('ReactNativeAttributePayload', () => {
113
diff({someStyle: [{foo: 1}, {bar: 2}]}, {}, validStyleAttribute),
114
).toEqual({foo: null, bar: null});
115
117
- const barStyle = ReactNativePropRegistry.register({
116
+ const barStyle = {
117
bar: 3,
119
- });
118
+ };
119
120
expect(
121
diff(
scripts/rollup/shims/react-native/ReactNativePropRegistry.js
deleted
-18
@@ -1,18 +0,0 @@
1
-/**
2
- * Copyright (c) 2013-present, Facebook, Inc.
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
- * @providesModule ReactNativePropRegistry
8
- * @flow
9
- */
10
-
11
-'use strict';
12
-
13
-const {
14
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
15
-} = require('ReactNative');
16
-
17
-module.exports =
18
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativePropRegistry;