react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ui / ReactDOMIDOperations.js
81155 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 ReactDOMIDOperations9* @typechecks static-only10*/1112/*jslint evil: true */1314"use strict";1516var CSSPropertyOperations = require('CSSPropertyOperations');17var DOMChildrenOperations = require('DOMChildrenOperations');18var DOMPropertyOperations = require('DOMPropertyOperations');19var ReactMount = require('ReactMount');20var ReactPerf = require('ReactPerf');2122var invariant = require('invariant');23var setInnerHTML = require('setInnerHTML');2425/**26* Errors for properties that should not be updated with `updatePropertyById()`.27*28* @type {object}29* @private30*/31var INVALID_PROPERTY_ERRORS = {32dangerouslySetInnerHTML:33'`dangerouslySetInnerHTML` must be set using `updateInnerHTMLByID()`.',34style: '`style` must be set using `updateStylesByID()`.'35};3637/**38* Operations used to process updates to DOM nodes. This is made injectable via39* `ReactComponent.BackendIDOperations`.40*/41var ReactDOMIDOperations = {4243/**44* Updates a DOM node with new property values. This should only be used to45* update DOM properties in `DOMProperty`.46*47* @param {string} id ID of the node to update.48* @param {string} name A valid property name, see `DOMProperty`.49* @param {*} value New value of the property.50* @internal51*/52updatePropertyByID: ReactPerf.measure(53'ReactDOMIDOperations',54'updatePropertyByID',55function(id, name, value) {56var node = ReactMount.getNode(id);57invariant(58!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),59'updatePropertyByID(...): %s',60INVALID_PROPERTY_ERRORS[name]61);6263// If we're updating to null or undefined, we should remove the property64// from the DOM node instead of inadvertantly setting to a string. This65// brings us in line with the same behavior we have on initial render.66if (value != null) {67DOMPropertyOperations.setValueForProperty(node, name, value);68} else {69DOMPropertyOperations.deleteValueForProperty(node, name);70}71}72),7374/**75* Updates a DOM node to remove a property. This should only be used to remove76* DOM properties in `DOMProperty`.77*78* @param {string} id ID of the node to update.79* @param {string} name A property name to remove, see `DOMProperty`.80* @internal81*/82deletePropertyByID: ReactPerf.measure(83'ReactDOMIDOperations',84'deletePropertyByID',85function(id, name, value) {86var node = ReactMount.getNode(id);87invariant(88!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),89'updatePropertyByID(...): %s',90INVALID_PROPERTY_ERRORS[name]91);92DOMPropertyOperations.deleteValueForProperty(node, name, value);93}94),9596/**97* Updates a DOM node with new style values. If a value is specified as '',98* the corresponding style property will be unset.99*100* @param {string} id ID of the node to update.101* @param {object} styles Mapping from styles to values.102* @internal103*/104updateStylesByID: ReactPerf.measure(105'ReactDOMIDOperations',106'updateStylesByID',107function(id, styles) {108var node = ReactMount.getNode(id);109CSSPropertyOperations.setValueForStyles(node, styles);110}111),112113/**114* Updates a DOM node's innerHTML.115*116* @param {string} id ID of the node to update.117* @param {string} html An HTML string.118* @internal119*/120updateInnerHTMLByID: ReactPerf.measure(121'ReactDOMIDOperations',122'updateInnerHTMLByID',123function(id, html) {124var node = ReactMount.getNode(id);125setInnerHTML(node, html);126}127),128129/**130* Updates a DOM node's text content set by `props.content`.131*132* @param {string} id ID of the node to update.133* @param {string} content Text content.134* @internal135*/136updateTextContentByID: ReactPerf.measure(137'ReactDOMIDOperations',138'updateTextContentByID',139function(id, content) {140var node = ReactMount.getNode(id);141DOMChildrenOperations.updateTextContent(node, content);142}143),144145/**146* Replaces a DOM node that exists in the document with markup.147*148* @param {string} id ID of child to be replaced.149* @param {string} markup Dangerous markup to inject in place of child.150* @internal151* @see {Danger.dangerouslyReplaceNodeWithMarkup}152*/153dangerouslyReplaceNodeWithMarkupByID: ReactPerf.measure(154'ReactDOMIDOperations',155'dangerouslyReplaceNodeWithMarkupByID',156function(id, markup) {157var node = ReactMount.getNode(id);158DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);159}160),161162/**163* Updates a component's children by processing a series of updates.164*165* @param {array<object>} updates List of update configurations.166* @param {array<string>} markup List of markup strings.167* @internal168*/169dangerouslyProcessChildrenUpdates: ReactPerf.measure(170'ReactDOMIDOperations',171'dangerouslyProcessChildrenUpdates',172function(updates, markup) {173for (var i = 0; i < updates.length; i++) {174updates[i].parentNode = ReactMount.getNode(updates[i].parentID);175}176DOMChildrenOperations.processUpdates(updates, markup);177}178)179};180181module.exports = ReactDOMIDOperations;182183184