diff options
Diffstat (limited to 'node_modules/react-dom/lib/ReactMarkupChecksum.js')
-rw-r--r-- | node_modules/react-dom/lib/ReactMarkupChecksum.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/node_modules/react-dom/lib/ReactMarkupChecksum.js b/node_modules/react-dom/lib/ReactMarkupChecksum.js new file mode 100644 index 000000000..fda495bdf --- /dev/null +++ b/node_modules/react-dom/lib/ReactMarkupChecksum.js @@ -0,0 +1,49 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ + +'use strict'; + +var adler32 = require('./adler32'); + +var TAG_END = /\/?>/; +var COMMENT_START = /^<\!\-\-/; + +var ReactMarkupChecksum = { + CHECKSUM_ATTR_NAME: 'data-react-checksum', + + /** + * @param {string} markup Markup string + * @return {string} Markup string with checksum attribute attached + */ + addChecksumToMarkup: function (markup) { + var checksum = adler32(markup); + + // Add checksum (handle both parent tags, comments and self-closing tags) + if (COMMENT_START.test(markup)) { + return markup; + } else { + return markup.replace(TAG_END, ' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '"$&'); + } + }, + + /** + * @param {string} markup to use + * @param {DOMElement} element root React element + * @returns {boolean} whether or not the markup is the same + */ + canReuseMarkup: function (markup, element) { + var existingChecksum = element.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME); + existingChecksum = existingChecksum && parseInt(existingChecksum, 10); + var markupChecksum = adler32(markup); + return markupChecksum === existingChecksum; + } +}; + +module.exports = ReactMarkupChecksum;
\ No newline at end of file |