void AttributeApplicator::removeOptimisticViewMutation()

in RenderCore/View/ComponentViewManager.mm [369:405]


void AttributeApplicator::removeOptimisticViewMutation(CKOptimisticMutationToken token) noexcept
{
  if (token == CKOptimisticMutationTokenNull) {
    return;
  }

  UIView *view = ((CKOptimisticViewMutationTokenWrapper *)token)->_view;

  if (view == nullptr) {
    return;
  }

  CKComponentAttributeSetWrapper *const wrapper = attributeSetWrapperForView(view);

  if (wrapper->_tokenSerialBaseline > ((CKOptimisticViewMutationTokenWrapper *)token)->_serial) {
    // Token no longer valid or relevant because the associated view recycled
    return;
  }

  for (auto it = wrapper->_optimisticViewMutations.begin(); it != wrapper->_optimisticViewMutations.end(); ++it) {
    if (it->serial == ((CKOptimisticViewMutationTokenWrapper *)token)->_serial) {
      if (wrapper->_optimisticViewMutations.size() == 1) {
        if (it->undo) {
          it->undo(view);
        }
      }
      wrapper->_optimisticViewMutations.erase(it);
      break;
    }
  }

  if (!wrapper->_suppressApply) {
    for (auto optimisticMutation : wrapper->_optimisticViewMutations) {
      optimisticMutation.apply(view);
    }
  }
}