@samitouri / QOS-React-2 / commits / fc341c5537

Inline createFullPageComponent in ReactDOMComponent

Ben Alpert committed Jun 2, 2015 at 17:23 UTC fc341c55372d8672d267ef023bb19ce669a6794a
4 files changed +20 -67
src/renderers/dom/client/__tests__/ReactRenderDocument-test.js
+1 -1
@@ -20,7 +20,7 @@ var getTestDocument;
20 var testDocument;
21
22 var UNMOUNT_INVARIANT_MESSAGE =
23 - 'Invariant Violation: ReactFullPageComponenthtml tried to unmount. ' +
23 + 'Invariant Violation: <html> tried to unmount. ' +
24 'Because of cross-browser quirks it is impossible to unmount some ' +
25 'top-level components (eg <html>, <head>, and <body>) reliably and ' +
26 'efficiently. To fix this, have a single top-level component that ' +
src/renderers/dom/client/wrappers/createFullPageComponent.js deleted
-58
@@ -1,58 +0,0 @@
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 - * @providesModule createFullPageComponent
10 - * @typechecks
11 - */
12 -
13 -'use strict';
14 -
15 -// Defeat circular references by requiring this directly.
16 -var ReactClass = require('ReactClass');
17 -var ReactElement = require('ReactElement');
18 -
19 -var invariant = require('invariant');
20 -
21 -/**
22 - * Create a component that will throw an exception when unmounted.
23 - *
24 - * Components like <html> <head> and <body> can't be removed or added
25 - * easily in a cross-browser way, however it's valuable to be able to
26 - * take advantage of React's reconciliation for styling and <title>
27 - * management. So we just document it and throw in dangerous cases.
28 - *
29 - * @param {string} tag The tag to wrap
30 - * @return {function} convenience constructor of new component
31 - */
32 -function createFullPageComponent(tag) {
33 - var elementFactory = ReactElement.createFactory(tag);
34 -
35 - var FullPageComponent = ReactClass.createClass({
36 - tagName: tag.toUpperCase(),
37 - displayName: 'ReactFullPageComponent' + tag,
38 -
39 - componentWillUnmount: function() {
40 - invariant(
41 - false,
42 - '%s tried to unmount. Because of cross-browser quirks it is ' +
43 - 'impossible to unmount some top-level components (eg <html>, <head>, ' +
44 - 'and <body>) reliably and efficiently. To fix this, have a single ' +
45 - 'top-level component that never unmounts render these elements.',
46 - this.constructor.displayName
47 - );
48 - },
49 -
50 - render: function() {
51 - return elementFactory(this.props);
52 - },
53 - });
54 -
55 - return FullPageComponent;
56 -}
57 -
58 -module.exports = createFullPageComponent;
src/renderers/dom/shared/ReactDOMComponent.js
+19
@@ -646,6 +646,25 @@ ReactDOMComponent.Mixin = {
646 case 'input':
647 ReactDOMInput.unmountWrapper(this);
648 break;
649 + case 'html':
650 + case 'head':
651 + case 'body':
652 + /**
653 + * Components like <html> <head> and <body> can't be removed or added
654 + * easily in a cross-browser way, however it's valuable to be able to
655 + * take advantage of React's reconciliation for styling and <title>
656 + * management. So we just document it and throw in dangerous cases.
657 + */
658 + invariant(
659 + false,
660 + '<%s> tried to unmount. Because of cross-browser quirks it is ' +
661 + 'impossible to unmount some top-level components (eg <html>, ' +
662 + '<head>, and <body>) reliably and efficiently. To fix this, have a ' +
663 + 'single top-level component that never unmounts render these ' +
664 + 'elements.',
665 + this._tag
666 + );
667 + break;
668 }
669
670 this.unmountChildren();
src/renderers/dom/shared/ReactDefaultInjection.js
-8
@@ -45,8 +45,6 @@ var ServerReactRootIndex = require('ServerReactRootIndex');
45 var SimpleEventPlugin = require('SimpleEventPlugin');
46 var SVGDOMPropertyConfig = require('SVGDOMPropertyConfig');
47
48 -var createFullPageComponent = require('createFullPageComponent');
49 -
48 function autoGenerateWrapperClass(type) {
49 return ReactClass.createClass({
50 tagName: type.toUpperCase(),
@@ -110,8 +108,6 @@ function inject() {
108 autoGenerateWrapperClass
109 );
110
113 - // This needs to happen before createFullPageComponent() otherwise the mixin
114 - // won't be included.
111 ReactInjection.Class.injectMixin(ReactBrowserComponentMixin);
112
113 ReactInjection.NativeComponent.injectComponentClasses({
@@ -122,10 +118,6 @@ function inject() {
118 'option': ReactDOMOption,
119 'select': ReactDOMSelect,
120 'textarea': ReactDOMTextarea,
125 -
126 - 'html': createFullPageComponent('html'),
127 - 'head': createFullPageComponent('head'),
128 - 'body': createFullPageComponent('body'),
121 });
122
123 ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig);