/**1* Copyright 2013-2015, 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* `ReactDOMComponent.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: function(id, name, value) {53var node = ReactMount.getNode(id);54("production" !== process.env.NODE_ENV ? invariant(55!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),56'updatePropertyByID(...): %s',57INVALID_PROPERTY_ERRORS[name]58) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));5960// If we're updating to null or undefined, we should remove the property61// from the DOM node instead of inadvertantly setting to a string. This62// brings us in line with the same behavior we have on initial render.63if (value != null) {64DOMPropertyOperations.setValueForProperty(node, name, value);65} else {66DOMPropertyOperations.deleteValueForProperty(node, name);67}68},6970/**71* Updates a DOM node to remove a property. This should only be used to remove72* DOM properties in `DOMProperty`.73*74* @param {string} id ID of the node to update.75* @param {string} name A property name to remove, see `DOMProperty`.76* @internal77*/78deletePropertyByID: function(id, name, value) {79var node = ReactMount.getNode(id);80("production" !== process.env.NODE_ENV ? invariant(81!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),82'updatePropertyByID(...): %s',83INVALID_PROPERTY_ERRORS[name]84) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));85DOMPropertyOperations.deleteValueForProperty(node, name, value);86},8788/**89* Updates a DOM node with new style values. If a value is specified as '',90* the corresponding style property will be unset.91*92* @param {string} id ID of the node to update.93* @param {object} styles Mapping from styles to values.94* @internal95*/96updateStylesByID: function(id, styles) {97var node = ReactMount.getNode(id);98CSSPropertyOperations.setValueForStyles(node, styles);99},100101/**102* Updates a DOM node's innerHTML.103*104* @param {string} id ID of the node to update.105* @param {string} html An HTML string.106* @internal107*/108updateInnerHTMLByID: function(id, html) {109var node = ReactMount.getNode(id);110setInnerHTML(node, html);111},112113/**114* Updates a DOM node's text content set by `props.content`.115*116* @param {string} id ID of the node to update.117* @param {string} content Text content.118* @internal119*/120updateTextContentByID: function(id, content) {121var node = ReactMount.getNode(id);122DOMChildrenOperations.updateTextContent(node, content);123},124125/**126* Replaces a DOM node that exists in the document with markup.127*128* @param {string} id ID of child to be replaced.129* @param {string} markup Dangerous markup to inject in place of child.130* @internal131* @see {Danger.dangerouslyReplaceNodeWithMarkup}132*/133dangerouslyReplaceNodeWithMarkupByID: function(id, markup) {134var node = ReactMount.getNode(id);135DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);136},137138/**139* Updates a component's children by processing a series of updates.140*141* @param {array<object>} updates List of update configurations.142* @param {array<string>} markup List of markup strings.143* @internal144*/145dangerouslyProcessChildrenUpdates: function(updates, markup) {146for (var i = 0; i < updates.length; i++) {147updates[i].parentNode = ReactMount.getNode(updates[i].parentID);148}149DOMChildrenOperations.processUpdates(updates, markup);150}151};152153ReactPerf.measureMethods(ReactDOMIDOperations, 'ReactDOMIDOperations', {154updatePropertyByID: 'updatePropertyByID',155deletePropertyByID: 'deletePropertyByID',156updateStylesByID: 'updateStylesByID',157updateInnerHTMLByID: 'updateInnerHTMLByID',158updateTextContentByID: 'updateTextContentByID',159dangerouslyReplaceNodeWithMarkupByID: 'dangerouslyReplaceNodeWithMarkupByID',160dangerouslyProcessChildrenUpdates: 'dangerouslyProcessChildrenUpdates'161});162163module.exports = ReactDOMIDOperations;164165166