react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / core / ReactEmptyComponent.js
81152 views/**1* Copyright 2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule ReactEmptyComponent9*/1011"use strict";1213var ReactElement = require('ReactElement');1415var invariant = require('invariant');1617var component;18// This registry keeps track of the React IDs of the components that rendered to19// `null` (in reality a placeholder such as `noscript`)20var nullComponentIdsRegistry = {};2122var ReactEmptyComponentInjection = {23injectEmptyComponent: function(emptyComponent) {24component = ReactElement.createFactory(emptyComponent);25}26};2728/**29* @return {ReactComponent} component The injected empty component.30*/31function getEmptyComponent() {32invariant(33component,34'Trying to return null from a render, but no null placeholder component ' +35'was injected.'36);37return component();38}3940/**41* Mark the component as having rendered to null.42* @param {string} id Component's `_rootNodeID`.43*/44function registerNullComponentID(id) {45nullComponentIdsRegistry[id] = true;46}4748/**49* Unmark the component as having rendered to null: it renders to something now.50* @param {string} id Component's `_rootNodeID`.51*/52function deregisterNullComponentID(id) {53delete nullComponentIdsRegistry[id];54}5556/**57* @param {string} id Component's `_rootNodeID`.58* @return {boolean} True if the component is rendered to null.59*/60function isNullComponentID(id) {61return nullComponentIdsRegistry[id];62}6364var ReactEmptyComponent = {65deregisterNullComponentID: deregisterNullComponentID,66getEmptyComponent: getEmptyComponent,67injection: ReactEmptyComponentInjection,68isNullComponentID: isNullComponentID,69registerNullComponentID: registerNullComponentID70};7172module.exports = ReactEmptyComponent;737475