Ejemplo n.º 1
0
 processChildDOMOperationsQueue: function() {
   if (this.domOperations) {
     ReactComponent.DOMIDOperations
       .manageChildrenByParentID(this._rootNodeID, this.domOperations);
     this.domOperations = null;
   }
 },
Ejemplo n.º 2
0
 function(transaction, prevProps, prevOwner, prevState, prevContext) {
   ReactComponent.Mixin.updateComponent.call(
     this,
     transaction,
     prevProps,
     prevOwner
   );
   var prevComponent = this._renderedComponent;
   var nextComponent = this._renderValidatedComponent();
   if (shouldUpdateReactComponent(prevComponent, nextComponent)) {
     prevComponent.receiveComponent(nextComponent, transaction);
   } else {
     // These two IDs are actually the same! But nothing should rely on that.
     var thisID = this._rootNodeID;
     var prevComponentID = prevComponent._rootNodeID;
     prevComponent.unmountComponent();
     this._renderedComponent = nextComponent;
     var nextMarkup = nextComponent.mountComponent(
       thisID,
       transaction,
       this._mountDepth + 1
     );
     ReactComponent.DOMIDOperations.dangerouslyReplaceNodeWithMarkupByID(
       prevComponentID,
       nextMarkup
     );
   }
 }
Ejemplo n.º 3
0
 receiveProps: function(nextProps, transaction) {
   if (nextProps.text !== this.props.text) {
     this.props.text = nextProps.text;
     ReactComponent.DOMIDOperations.updateTextContentByID(
       this._rootNodeID,
       nextProps.text
     );
   }
 }
Ejemplo n.º 4
0
/**
 * Processes any enqueued updates.
 *
 * @private
 */
function processQueue() {
  if (updateQueue.length) {
    ReactComponent.DOMIDOperations.dangerouslyProcessChildrenUpdates(
      updateQueue,
      markupQueue
    );
    clearQueue();
  }
}
Ejemplo n.º 5
0
  _updateDOMChildren: function(nextProps, transaction) {
    var thisPropsContentType = typeof this.props.content;
    var thisPropsContentEmpty =
      this.props.content == null || thisPropsContentType === 'boolean';
    var nextPropsContentType = typeof nextProps.content;
    var nextPropsContentEmpty =
      nextProps.content == null || nextPropsContentType === 'boolean';

    var lastUsedContent = !thisPropsContentEmpty ? this.props.content :
      CONTENT_TYPES[typeof this.props.children] ? this.props.children : null;

    var contentToUse = !nextPropsContentEmpty ? nextProps.content :
      CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null;

    // Note the use of `!=` which checks for null or undefined.

    var lastUsedChildren =
      lastUsedContent != null ? null : this.props.children;
    var childrenToUse = contentToUse != null ? null : nextProps.children;

    if (contentToUse != null) {
      var childrenRemoved = lastUsedChildren != null && childrenToUse == null;
      if (childrenRemoved) {
        this.updateMultiChild(null, transaction);
      }
      if (lastUsedContent !== contentToUse) {
        ReactComponent.DOMIDOperations.updateTextContentByID(
          this._rootNodeID,
          '' + contentToUse
        );
      }
    } else {
      var contentRemoved = lastUsedContent != null && contentToUse == null;
      if (contentRemoved) {
        ReactComponent.DOMIDOperations.updateTextContentByID(
          this._rootNodeID,
          ''
        );
      }
      this.updateMultiChild(flattenChildren(nextProps.children), transaction);
    }
  },
Ejemplo n.º 6
0
 updateComponent: function(transaction) {
   var currentComponent = this._renderedComponent;
   var nextComponent = this._renderValidatedComponent();
   if (currentComponent.constructor === nextComponent.constructor) {
     currentComponent.receiveProps(nextComponent.props, transaction);
   } else {
     // These two IDs are actually the same! But nothing should rely on that.
     var thisID = this._rootNodeID;
     var currentComponentID = currentComponent._rootNodeID;
     currentComponent.unmountComponent();
     var nextMarkup = nextComponent.mountComponent(thisID, transaction);
     ReactComponent.DOMIDOperations.dangerouslyReplaceNodeWithMarkupByID(
       currentComponentID,
       nextMarkup
     );
     this._renderedComponent = nextComponent;
   }
 },
Ejemplo n.º 7
0
  _updateDOMChildren: function(lastProps, transaction) {
    var nextProps = this.props;

    var lastContent =
      CONTENT_TYPES[typeof lastProps.children] ? lastProps.children : null;
    var nextContent =
      CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null;

    var lastHtml =
      lastProps.dangerouslySetInnerHTML &&
      lastProps.dangerouslySetInnerHTML.__html;
    var nextHtml =
      nextProps.dangerouslySetInnerHTML &&
      nextProps.dangerouslySetInnerHTML.__html;

    // Note the use of `!=` which checks for null or undefined.
    var lastChildren = lastContent != null ? null : lastProps.children;
    var nextChildren = nextContent != null ? null : nextProps.children;

    // If we're switching from children to content/html or vice versa, remove
    // the old content
    var lastHasContentOrHtml = lastContent != null || lastHtml != null;
    var nextHasContentOrHtml = nextContent != null || nextHtml != null;
    if (lastChildren != null && nextChildren == null) {
      this.updateChildren(null, transaction);
    } else if (lastHasContentOrHtml && !nextHasContentOrHtml) {
      this.updateTextContent('');
    }

    if (nextContent != null) {
      if (lastContent !== nextContent) {
        this.updateTextContent('' + nextContent);
      }
    } else if (nextHtml != null) {
      if (lastHtml !== nextHtml) {
        ReactComponent.DOMIDOperations.updateInnerHTMLByID(
          this._rootNodeID,
          nextHtml
        );
      }
    } else if (nextChildren != null) {
      this.updateChildren(nextChildren, transaction);
    }
  },
Ejemplo n.º 8
0
 _updateDOMProperties: function(lastProps) {
   var nextProps = this.props;
   var propKey;
   var styleName;
   var styleUpdates;
   for (propKey in lastProps) {
     if (nextProps.hasOwnProperty(propKey) ||
        !lastProps.hasOwnProperty(propKey)) {
       continue;
     }
     if (propKey === STYLE) {
       var lastStyle = lastProps[propKey];
       for (styleName in lastStyle) {
         if (lastStyle.hasOwnProperty(styleName)) {
           styleUpdates = styleUpdates || {};
           styleUpdates[styleName] = '';
         }
       }
     } else if (registrationNames[propKey]) {
       deleteListener(this._rootNodeID, propKey);
     } else if (
         DOMProperty.isStandardName[propKey] ||
         DOMProperty.isCustomAttribute(propKey)) {
       ReactComponent.DOMIDOperations.deletePropertyByID(
         this._rootNodeID,
         propKey
       );
     }
   }
   for (propKey in nextProps) {
     var nextProp = nextProps[propKey];
     var lastProp = lastProps[propKey];
     if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
       continue;
     }
     if (propKey === STYLE) {
       if (nextProp) {
         nextProp = nextProps.style = merge(nextProp);
       }
       if (lastProp) {
         // Unset styles on `lastProp` but not on `nextProp`.
         for (styleName in lastProp) {
           if (lastProp.hasOwnProperty(styleName) &&
               !nextProp.hasOwnProperty(styleName)) {
             styleUpdates = styleUpdates || {};
             styleUpdates[styleName] = '';
           }
         }
         // Update styles that changed since `lastProp`.
         for (styleName in nextProp) {
           if (nextProp.hasOwnProperty(styleName) &&
               lastProp[styleName] !== nextProp[styleName]) {
             styleUpdates = styleUpdates || {};
             styleUpdates[styleName] = nextProp[styleName];
           }
         }
       } else {
         // Relies on `updateStylesByID` not mutating `styleUpdates`.
         styleUpdates = nextProp;
       }
     } else if (registrationNames[propKey]) {
       putListener(this._rootNodeID, propKey, nextProp);
     } else if (
         DOMProperty.isStandardName[propKey] ||
         DOMProperty.isCustomAttribute(propKey)) {
       ReactComponent.DOMIDOperations.updatePropertyByID(
         this._rootNodeID,
         propKey,
         nextProp
       );
     }
   }
   if (styleUpdates) {
     ReactComponent.DOMIDOperations.updateStylesByID(
       this._rootNodeID,
       styleUpdates
     );
   }
 },
Ejemplo n.º 9
0
 _updateDOMProperties: function(nextProps) {
   var lastProps = this.props;
   var propKey;
   var styleName;
   var styleUpdates;
   for (propKey in lastProps) {
     if (nextProps.hasOwnProperty(propKey) ||
        !lastProps.hasOwnProperty(propKey)) {
       continue;
     }
     if (propKey === STYLE) {
       var lastStyle = lastProps[propKey];
       for (styleName in lastStyle) {
         if (lastStyle.hasOwnProperty(styleName)) {
           styleUpdates = styleUpdates || {};
           styleUpdates[styleName] = '';
         }
       }
     } else if (propKey === DANGEROUSLY_SET_INNER_HTML ||
                propKey === CONTENT) {
       ReactComponent.DOMIDOperations.updateTextContentByID(
         this._rootNodeID,
         ''
       );
     } else if (registrationNames[propKey]) {
       deleteListener(this._rootNodeID, propKey);
     } else {
       ReactComponent.DOMIDOperations.deletePropertyByID(
         this._rootNodeID,
         propKey
       );
     }
   }
   for (propKey in nextProps) {
     var nextProp = nextProps[propKey];
     var lastProp = lastProps[propKey];
     if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
       continue;
     }
     if (propKey === STYLE) {
       if (nextProp) {
         nextProp = nextProps.style = merge(nextProp);
       }
       if (lastProp) {
         // Unset styles on `lastProp` but not on `nextProp`.
         for (styleName in lastProp) {
           if (lastProp.hasOwnProperty(styleName) &&
               !nextProp.hasOwnProperty(styleName)) {
             styleUpdates = styleUpdates || {};
             styleUpdates[styleName] = '';
           }
         }
         // Update styles that changed since `lastProp`.
         for (styleName in nextProp) {
           if (nextProp.hasOwnProperty(styleName) &&
               lastProp[styleName] !== nextProp[styleName]) {
             styleUpdates = styleUpdates || {};
             styleUpdates[styleName] = nextProp[styleName];
           }
         }
       } else {
         // Relies on `updateStylesByID` not mutating `styleUpdates`.
         styleUpdates = nextProp;
       }
     } else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
       var lastHtml = lastProp && lastProp.__html;
       var nextHtml = nextProp && nextProp.__html;
       if (lastHtml !== nextHtml) {
         ReactComponent.DOMIDOperations.updateInnerHTMLByID(
           this._rootNodeID,
           nextProp
         );
       }
     } else if (propKey === CONTENT) {
       ReactComponent.DOMIDOperations.updateTextContentByID(
         this._rootNodeID,
         '' + nextProp
       );
     } else if (registrationNames[propKey]) {
       putListener(this._rootNodeID, propKey, nextProp);
     } else {
       ReactComponent.DOMIDOperations.updatePropertyByID(
         this._rootNodeID,
         propKey,
         nextProp
       );
     }
   }
   if (styleUpdates) {
     ReactComponent.DOMIDOperations.updateStylesByID(
       this._rootNodeID,
       styleUpdates
     );
   }
 },