Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2014, 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 ReactEmptyComponent
10
*/
11
12
"use strict";
13
14
var ReactElement = require('ReactElement');
15
16
var invariant = require('invariant');
17
18
var component;
19
// This registry keeps track of the React IDs of the components that rendered to
20
// `null` (in reality a placeholder such as `noscript`)
21
var nullComponentIdsRegistry = {};
22
23
var ReactEmptyComponentInjection = {
24
injectEmptyComponent: function(emptyComponent) {
25
component = ReactElement.createFactory(emptyComponent);
26
}
27
};
28
29
/**
30
* @return {ReactComponent} component The injected empty component.
31
*/
32
function getEmptyComponent() {
33
invariant(
34
component,
35
'Trying to return null from a render, but no null placeholder component ' +
36
'was injected.'
37
);
38
return component();
39
}
40
41
/**
42
* Mark the component as having rendered to null.
43
* @param {string} id Component's `_rootNodeID`.
44
*/
45
function registerNullComponentID(id) {
46
nullComponentIdsRegistry[id] = true;
47
}
48
49
/**
50
* Unmark the component as having rendered to null: it renders to something now.
51
* @param {string} id Component's `_rootNodeID`.
52
*/
53
function deregisterNullComponentID(id) {
54
delete nullComponentIdsRegistry[id];
55
}
56
57
/**
58
* @param {string} id Component's `_rootNodeID`.
59
* @return {boolean} True if the component is rendered to null.
60
*/
61
function isNullComponentID(id) {
62
return nullComponentIdsRegistry[id];
63
}
64
65
var ReactEmptyComponent = {
66
deregisterNullComponentID: deregisterNullComponentID,
67
getEmptyComponent: getEmptyComponent,
68
injection: ReactEmptyComponentInjection,
69
isNullComponentID: isNullComponentID,
70
registerNullComponentID: registerNullComponentID
71
};
72
73
module.exports = ReactEmptyComponent;
74
75