|
12 | 12 | 'use strict';
|
13 | 13 |
|
14 | 14 | var ReactElement = require('ReactElement');
|
15 |
| -var ReactInstanceMap = require('ReactInstanceMap'); |
| 15 | +var ReactEmptyComponentRegistry = require('ReactEmptyComponentRegistry'); |
| 16 | +var ReactReconciler = require('ReactReconciler'); |
16 | 17 |
|
17 |
| -var invariant = require('invariant'); |
| 18 | +var assign = require('Object.assign'); |
18 | 19 |
|
19 |
| -var component; |
20 |
| -// This registry keeps track of the React IDs of the components that rendered to |
21 |
| -// `null` (in reality a placeholder such as `noscript`) |
22 |
| -var nullComponentIDsRegistry = {}; |
| 20 | +var placeholderElement; |
23 | 21 |
|
24 | 22 | var ReactEmptyComponentInjection = {
|
25 |
| - injectEmptyComponent: function(emptyComponent) { |
26 |
| - component = ReactElement.createFactory(emptyComponent); |
| 23 | + injectEmptyComponent: function(component) { |
| 24 | + placeholderElement = ReactElement.createElement(component); |
27 | 25 | },
|
28 | 26 | };
|
29 | 27 |
|
30 |
| -var ReactEmptyComponentType = function() {}; |
31 |
| -ReactEmptyComponentType.isReactClass = {}; |
32 |
| -ReactEmptyComponentType.prototype.componentDidMount = function() { |
33 |
| - var internalInstance = ReactInstanceMap.get(this); |
34 |
| - // TODO: Make sure we run these methods in the correct order, we shouldn't |
35 |
| - // need this check. We're going to assume if we're here it means we ran |
36 |
| - // componentWillUnmount already so there is no internal instance (it gets |
37 |
| - // removed as part of the unmounting process). |
38 |
| - if (!internalInstance) { |
39 |
| - return; |
40 |
| - } |
41 |
| - registerNullComponentID(internalInstance._rootNodeID); |
| 28 | +var ReactEmptyComponent = function(instantiate) { |
| 29 | + this._currentElement = null; |
| 30 | + this._rootNodeID = null; |
| 31 | + this._renderedComponent = instantiate(placeholderElement); |
42 | 32 | };
|
43 |
| -ReactEmptyComponentType.prototype.componentWillUnmount = function() { |
44 |
| - var internalInstance = ReactInstanceMap.get(this); |
45 |
| - // TODO: Get rid of this check. See TODO in componentDidMount. |
46 |
| - if (!internalInstance) { |
47 |
| - return; |
48 |
| - } |
49 |
| - deregisterNullComponentID(internalInstance._rootNodeID); |
50 |
| -}; |
51 |
| -ReactEmptyComponentType.prototype.render = function() { |
52 |
| - invariant( |
53 |
| - component, |
54 |
| - 'Trying to return null from a render, but no null placeholder component ' + |
55 |
| - 'was injected.' |
56 |
| - ); |
57 |
| - return component(); |
58 |
| -}; |
59 |
| - |
60 |
| -var emptyElement = ReactElement.createElement(ReactEmptyComponentType); |
61 |
| - |
62 |
| -/** |
63 |
| - * Mark the component as having rendered to null. |
64 |
| - * @param {string} id Component's `_rootNodeID`. |
65 |
| - */ |
66 |
| -function registerNullComponentID(id) { |
67 |
| - nullComponentIDsRegistry[id] = true; |
68 |
| -} |
69 |
| - |
70 |
| -/** |
71 |
| - * Unmark the component as having rendered to null: it renders to something now. |
72 |
| - * @param {string} id Component's `_rootNodeID`. |
73 |
| - */ |
74 |
| -function deregisterNullComponentID(id) { |
75 |
| - delete nullComponentIDsRegistry[id]; |
76 |
| -} |
77 |
| - |
78 |
| -/** |
79 |
| - * @param {string} id Component's `_rootNodeID`. |
80 |
| - * @return {boolean} True if the component is rendered to null. |
81 |
| - */ |
82 |
| -function isNullComponentID(id) { |
83 |
| - return !!nullComponentIDsRegistry[id]; |
84 |
| -} |
| 33 | +assign(ReactEmptyComponent.prototype, { |
| 34 | + construct: function(element) { |
| 35 | + }, |
| 36 | + mountComponent: function(rootID, transaction, context) { |
| 37 | + ReactEmptyComponentRegistry.registerNullComponentID(rootID); |
| 38 | + this._rootNodeID = rootID; |
| 39 | + return ReactReconciler.mountComponent( |
| 40 | + this._renderedComponent, |
| 41 | + rootID, |
| 42 | + transaction, |
| 43 | + context |
| 44 | + ); |
| 45 | + }, |
| 46 | + receiveComponent: function() { |
| 47 | + }, |
| 48 | + unmountComponent: function(rootID, transaction, context) { |
| 49 | + ReactReconciler.unmountComponent(this._renderedComponent); |
| 50 | + ReactEmptyComponentRegistry.deregisterNullComponentID(this._rootNodeID); |
| 51 | + this._rootNodeID = null; |
| 52 | + this._renderedComponent = null; |
| 53 | + }, |
| 54 | +}); |
85 | 55 |
|
86 |
| -var ReactEmptyComponent = { |
87 |
| - emptyElement: emptyElement, |
88 |
| - injection: ReactEmptyComponentInjection, |
89 |
| - isNullComponentID: isNullComponentID, |
90 |
| -}; |
| 56 | +ReactEmptyComponent.injection = ReactEmptyComponentInjection; |
91 | 57 |
|
92 | 58 | module.exports = ReactEmptyComponent;
|
0 commit comments