public static void onCreateChangeSet()

in litho-sections-core/src/main/java/com/facebook/litho/sections/common/SingleComponentSectionSpec.java [58:159]


  public static void onCreateChangeSet(
      SectionContext context,
      ChangeSet changeSet,
      @Prop Diff<Component> component,
      @Prop(optional = true) Diff<Boolean> sticky,
      @Prop(optional = true) Diff<Integer> spanSize,
      @Prop(optional = true) Diff<Boolean> isFullSpan,
      @Prop(optional = true) Diff<Map<String, Object>> customAttributes,
      @Prop(optional = true) Diff<Object> data,
      @Prop(optional = true) Diff<ComponentsLogger> componentsLogger,
      @Prop(optional = true) Diff<String> logTag) {
    final Object prevData = data.getPrevious();
    final Object nextData = data.getNext();
    final Component prevComponent = component.getPrevious();
    final Component nextComponent = component.getNext();

    if (prevComponent == null && nextComponent == null) {
      return;
    }

    if (prevComponent != null && nextComponent == null) {
      changeSet.delete(0, prevData);
      return;
    }

    boolean isNextSticky = false;
    if (sticky != null && sticky.getNext() != null) {
      isNextSticky = sticky.getNext();
    }

    int nextSpanSize = 1;
    if (spanSize != null && spanSize.getNext() != null) {
      nextSpanSize = spanSize.getNext();
    }

    boolean isNextFullSpan = false;
    if (isFullSpan != null && isFullSpan.getNext() != null) {
      isNextFullSpan = isFullSpan.getNext();
    }

    if (prevComponent == null) {
      changeSet.insert(
          0,
          addCustomAttributes(
                  ComponentRenderInfo.create(),
                  customAttributes.getNext(),
                  context,
                  component,
                  componentsLogger)
              .component(nextComponent)
              .isSticky(isNextSticky)
              .spanSize(nextSpanSize)
              .isFullSpan(isNextFullSpan)
              .logTag(logTag != null ? logTag.getNext() : null)
              .build(),
          context.getTreePropsCopy(),
          nextData);
      return;
    }

    // Both previous and next components are non-null -- check if an update is required.
    boolean isPrevSticky = false;
    if (sticky != null && sticky.getPrevious() != null) {
      isPrevSticky = sticky.getPrevious();
    }

    int prevSpanSize = 1;
    if (spanSize != null && spanSize.getPrevious() != null) {
      prevSpanSize = spanSize.getPrevious();
    }

    boolean isPrevFullSpan = false;
    if (isFullSpan != null && isFullSpan.getPrevious() != null) {
      isPrevFullSpan = isFullSpan.getPrevious();
    }

    final boolean customAttributesEqual =
        MapDiffUtils.areMapsEqual(customAttributes.getPrevious(), customAttributes.getNext());

    if (isPrevSticky != isNextSticky
        || prevSpanSize != nextSpanSize
        || isPrevFullSpan != isNextFullSpan
        || !customAttributesEqual
        || !isComponentEquivalent(prevComponent, nextComponent)) {
      changeSet.update(
          0,
          addCustomAttributes(
                  ComponentRenderInfo.create(),
                  customAttributes.getNext(),
                  context,
                  component,
                  componentsLogger)
              .component(nextComponent)
              .isSticky(isNextSticky)
              .spanSize(nextSpanSize)
              .isFullSpan(isNextFullSpan)
              .build(),
          context.getTreePropsCopy(),
          prevData,
          nextData);
    }
  }