@samitouri / QOS-React-2 / commits / 27996377e0

Fetch DOM node lazily for updates

Previously, we fetched the node once for every changed attribute. In my createElement diff, I changed it to fetch the node (once) regardless of if there were changes -- fetching it once only if there are changes is even better.

Ben Alpert committed Sep 4, 2015 at 11:36 UTC 27996377e0da502b6d9fccd2018d7919c3de6733
1 file changed +14 -2
src/renderers/dom/shared/ReactDOMComponent.js
+14 -2
@@ -786,9 +786,8 @@ ReactDOMComponent.Mixin = {
786 break;
787 }
788
789 - var node = ReactMount.getNode(this._rootNodeID);
789 assertValidProps(this, nextProps);
791 - this._updateDOMProperties(lastProps, nextProps, transaction, node);
790 + this._updateDOMProperties(lastProps, nextProps, transaction, null);
791 this._updateDOMChildren(
792 lastProps,
793 nextProps,
@@ -822,6 +821,7 @@ ReactDOMComponent.Mixin = {
821 * @param {object} lastProps
822 * @param {object} nextProps
823 * @param {ReactReconcileTransaction} transaction
824 + * @param {?DOMElement} node
825 */
826 _updateDOMProperties: function(lastProps, nextProps, transaction, node) {
827 var propKey;
@@ -851,6 +851,9 @@ ReactDOMComponent.Mixin = {
851 } else if (
852 DOMProperty.properties[propKey] ||
853 DOMProperty.isCustomAttribute(propKey)) {
854 + if (!node) {
855 + node = ReactMount.getNode(this._rootNodeID);
856 + }
857 DOMPropertyOperations.deleteValueForProperty(node, propKey);
858 }
859 }
@@ -904,6 +907,9 @@ ReactDOMComponent.Mixin = {
907 deleteListener(this._rootNodeID, propKey);
908 }
909 } else if (isCustomComponent(this._tag, nextProps)) {
910 + if (!node) {
911 + node = ReactMount.getNode(this._rootNodeID);
912 + }
913 DOMPropertyOperations.setValueForAttribute(
914 node,
915 propKey,
@@ -912,6 +918,9 @@ ReactDOMComponent.Mixin = {
918 } else if (
919 DOMProperty.properties[propKey] ||
920 DOMProperty.isCustomAttribute(propKey)) {
921 + if (!node) {
922 + node = ReactMount.getNode(this._rootNodeID);
923 + }
924 // If we're updating to null or undefined, we should remove the property
925 // from the DOM node instead of inadvertantly setting to a string. This
926 // brings us in line with the same behavior we have on initial render.
@@ -923,6 +932,9 @@ ReactDOMComponent.Mixin = {
932 }
933 }
934 if (styleUpdates) {
935 + if (!node) {
936 + node = ReactMount.getNode(this._rootNodeID);
937 + }
938 CSSPropertyOperations.setValueForStyles(node, styleUpdates);
939 }
940 },