react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ReactTextComponent.js
81152 views/**1* Copyright 2013-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 ReactTextComponent9* @typechecks static-only10*/1112"use strict";1314var DOMPropertyOperations = require('DOMPropertyOperations');15var ReactComponent = require('ReactComponent');16var ReactElement = require('ReactElement');1718var assign = require('Object.assign');19var escapeTextForBrowser = require('escapeTextForBrowser');2021/**22* Text nodes violate a couple assumptions that React makes about components:23*24* - When mounting text into the DOM, adjacent text nodes are merged.25* - Text nodes cannot be assigned a React root ID.26*27* This component is used to wrap strings in elements so that they can undergo28* the same reconciliation that is applied to elements.29*30* TODO: Investigate representing React components in the DOM with text nodes.31*32* @class ReactTextComponent33* @extends ReactComponent34* @internal35*/36var ReactTextComponent = function(props) {37// This constructor and it's argument is currently used by mocks.38};3940assign(ReactTextComponent.prototype, ReactComponent.Mixin, {4142/**43* Creates the markup for this text node. This node is not intended to have44* any features besides containing text content.45*46* @param {string} rootID DOM ID of the root node.47* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction48* @param {number} mountDepth number of components in the owner hierarchy49* @return {string} Markup for this text node.50* @internal51*/52mountComponent: function(rootID, transaction, mountDepth) {53ReactComponent.Mixin.mountComponent.call(54this,55rootID,56transaction,57mountDepth58);5960var escapedText = escapeTextForBrowser(this.props);6162if (transaction.renderToStaticMarkup) {63// Normally we'd wrap this in a `span` for the reasons stated above, but64// since this is a situation where React won't take over (static pages),65// we can simply return the text as it is.66return escapedText;67}6869return (70'<span ' + DOMPropertyOperations.createMarkupForID(rootID) + '>' +71escapedText +72'</span>'73);74},7576/**77* Updates this component by updating the text content.78*79* @param {object} nextComponent Contains the next text content.80* @param {ReactReconcileTransaction} transaction81* @internal82*/83receiveComponent: function(nextComponent, transaction) {84var nextProps = nextComponent.props;85if (nextProps !== this.props) {86this.props = nextProps;87ReactComponent.BackendIDOperations.updateTextContentByID(88this._rootNodeID,89nextProps90);91}92}9394});9596var ReactTextComponentFactory = function(text) {97// Bypass validation and configuration98return new ReactElement(ReactTextComponent, null, null, null, null, text);99};100101ReactTextComponentFactory.type = ReactTextComponent;102103module.exports = ReactTextComponentFactory;104105106