@samitouri / QOS-React-2 / commits / 5f5cfe80f2

Removed unnecessary RN fiber "topsecret-" prefix (#9837)

* Removed RN fiber 'topsecret-' prefix * Added a test to ensure that duplicate view-names can't be registered with createReactNativeComponentClass

Brian Vaughn committed Jun 2, 2017 at 07:57 UTC 5f5cfe80f265d80f85ba1a13ce5131f509260cfb
4 files changed +75 -12
scripts/fiber/tests-passing.txt
+4
@@ -1710,6 +1710,10 @@ src/renderers/native/__tests__/ReactNativeMount-test.js
1710 * returns the correct instance and calls it in the callback
1711 * renders and reorders children
1712
1713 +src/renderers/native/__tests__/createReactNativeComponentClass-test.js
1714 +* should register viewConfigs
1715 +* should not allow viewConfigs with duplicate uiViewClassNames to be registered
1716 +
1717 src/renderers/shared/__tests__/ReactDOMFrameScheduling-test.js
1718 * throws when requestAnimationFrame is not polyfilled in the browser
1719 * can import findDOMNode in Node environment
src/renderers/native/ReactNativeFiberInspector.js
+1 -4
@@ -76,12 +76,9 @@ if (__DEV__) {
76 return null;
77 };
78
79 - var stripTopSecret = str =>
80 - typeof str === 'string' && str.replace('topsecret-', '');
81 -
79 var createHierarchy = function(fiberHierarchy) {
80 return fiberHierarchy.map(fiber => ({
84 - name: stripTopSecret(getComponentName(fiber)),
81 + name: getComponentName(fiber),
82 getInspectorData: findNodeHandle => ({
83 measure: callback =>
84 UIManager.measure(getHostNode(fiber, findNodeHandle), callback),
src/renderers/native/ReactNativeViewConfigRegistry.js
+5 -8
@@ -22,8 +22,6 @@ export type ReactNativeBaseComponentViewConfig = {
22
23 const viewConfigs = new Map();
24
25 -const prefix = 'topsecret-';
26 -
25 const ReactNativeViewConfigRegistry = {
26 register(viewConfig: ReactNativeBaseComponentViewConfig) {
27 const name = viewConfig.uiViewClassName;
@@ -32,13 +30,12 @@ const ReactNativeViewConfigRegistry = {
30 'Tried to register two views with the same name %s',
31 name,
32 );
35 - const secretName = prefix + name;
36 - viewConfigs.set(secretName, viewConfig);
37 - return secretName;
33 + viewConfigs.set(name, viewConfig);
34 + return name;
35 },
39 - get(secretName: string) {
40 - const config = viewConfigs.get(secretName);
41 - invariant(config, 'View config not found for name %s', secretName);
36 + get(name: string) {
37 + const config = viewConfigs.get(name);
38 + invariant(config, 'View config not found for name %s', name);
39 return config;
40 },
41 };
src/renderers/native/__tests__/createReactNativeComponentClass-test.js new
+65
@@ -0,0 +1,65 @@
1 +/**
2 + * Copyright 2013-2015, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @emails react-core
10 + */
11 +
12 +'use strict';
13 +
14 +let createReactNativeComponentClass;
15 +let React;
16 +let ReactNative;
17 +let ReactNativeFeatureFlags = require('ReactNativeFeatureFlags');
18 +
19 +describe('createReactNativeComponentClass', () => {
20 + beforeEach(() => {
21 + jest.resetModules();
22 +
23 + createReactNativeComponentClass = require('createReactNativeComponentClass');
24 + React = require('React');
25 + ReactNative = require('ReactNative');
26 + });
27 +
28 + it('should register viewConfigs', () => {
29 + const textViewConfig = {
30 + validAttributes: {},
31 + uiViewClassName: 'Text',
32 + };
33 + const viewViewConfig = {
34 + validAttributes: {},
35 + uiViewClassName: 'View',
36 + };
37 +
38 + const Text = createReactNativeComponentClass(textViewConfig);
39 + const View = createReactNativeComponentClass(viewViewConfig);
40 +
41 + expect(Text).not.toBe(View);
42 +
43 + ReactNative.render(<Text />, 1);
44 + ReactNative.render(<View />, 1);
45 + });
46 +
47 + if (ReactNativeFeatureFlags.useFiber) {
48 + it('should not allow viewConfigs with duplicate uiViewClassNames to be registered', () => {
49 + const textViewConfig = {
50 + validAttributes: {},
51 + uiViewClassName: 'Text',
52 + };
53 + const altTextViewConfig = {
54 + validAttributes: {},
55 + uiViewClassName: 'Text', // Same
56 + };
57 +
58 + createReactNativeComponentClass(textViewConfig);
59 +
60 + expect(() => {
61 + createReactNativeComponentClass(altTextViewConfig);
62 + }).toThrow('Tried to register two views with the same name Text');
63 + });
64 + }
65 +});