コード例 #1
0
function diffNestedProperty(
  updatePayload :? Object,
  prevProp, // inferred
  nextProp, // inferred
  validAttributes : AttributeConfiguration
) : ?Object {
  // The style property is a deeply nested element which includes numbers
  // to represent static objects. Most of the time, it doesn't change across
  // renders, so it's faster to spend the time checking if it is different
  // before actually doing the expensive flattening operation in order to
  // compute the diff.
  if (!styleDiffer(prevProp, nextProp)) {
    return updatePayload;
  }

  // TODO: Walk both props in parallel instead of flattening.

  var previousFlattenedStyle = flattenStyle(prevProp);
  var nextFlattenedStyle = flattenStyle(nextProp);

  if (!previousFlattenedStyle || !nextFlattenedStyle) {
    if (nextFlattenedStyle) {
      return addProperties(
        updatePayload,
        nextFlattenedStyle,
        validAttributes
      );
    }
    if (previousFlattenedStyle) {
      return clearProperties(
        updatePayload,
        previousFlattenedStyle,
        validAttributes
      );
    }
    return updatePayload;
  }

  // recurse
  return diffProperties(
    updatePayload,
    previousFlattenedStyle,
    nextFlattenedStyle,
    validAttributes
  );
}
コード例 #2
0
  computeUpdatedProperties: function(prevProps, nextProps, validAttributes) {
    if (__DEV__) {
      for (var key in nextProps) {
        if (nextProps.hasOwnProperty(key) &&
            nextProps[key] &&
            validAttributes[key]) {
          deepFreezeAndThrowOnMutationInDev(nextProps[key]);
        }
      }
    }

    var updatePayload = diffRawProperties(
      null, // updatePayload
      prevProps,
      nextProps,
      validAttributes
    );

    // The style property is a deeply nested element which includes numbers
    // to represent static objects. Most of the time, it doesn't change across
    // renders, so it's faster to spend the time checking if it is different
    // before actually doing the expensive flattening operation in order to
    // compute the diff.
    if (styleDiffer(nextProps.style, prevProps.style)) {
      var nextFlattenedStyle = precomputeStyle(flattenStyle(nextProps.style));
      updatePayload = diffRawProperties(
        updatePayload,
        this.previousFlattenedStyle,
        nextFlattenedStyle,
        ReactNativeStyleAttributes
      );
      this.previousFlattenedStyle = nextFlattenedStyle;
    }

    return updatePayload;
  },