MountingTransaction.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <react/mounting/MountingTelemetry.h>
  9. #include <react/mounting/ShadowViewMutation.h>
  10. namespace facebook {
  11. namespace react {
  12. /*
  13. * Encapsulates all artifacts of `ShadowTree` commit (or a series of them),
  14. * particularly list of mutations and meta-data associated with the commit.
  15. * Movable and copyable, but moving is strongly encouraged.
  16. * Beware: A moved-from object of this type has unspecified value and accessing
  17. * that is UB.
  18. */
  19. class MountingTransaction final {
  20. public:
  21. /*
  22. * A Number (or revision) grows continuously starting from `1`. Value `0`
  23. * represents the state before the very first transaction happens.
  24. */
  25. using Number = int64_t;
  26. /*
  27. * Copying a list of `ShadowViewMutation` is expensive, so the constructor
  28. * accepts it as rvalue reference to discourage copying.
  29. */
  30. MountingTransaction(
  31. SurfaceId surfaceId,
  32. Number number,
  33. ShadowViewMutationList &&mutations,
  34. MountingTelemetry telemetry);
  35. /*
  36. * Copy semantic.
  37. * Copying of MountingTransaction is expensive, so copy-constructor is
  38. * explicit and copy-assignment is deleted to prevent accidental copying.
  39. */
  40. explicit MountingTransaction(const MountingTransaction &mountingTransaction) =
  41. default;
  42. MountingTransaction &operator=(const MountingTransaction &other) = delete;
  43. /*
  44. * Move semantic.
  45. */
  46. MountingTransaction(MountingTransaction &&mountingTransaction) noexcept =
  47. default;
  48. MountingTransaction &operator=(MountingTransaction &&other) = default;
  49. /*
  50. * Returns a list of mutations that represent the transaction. The list can be
  51. * empty (theoretically).
  52. */
  53. ShadowViewMutationList const &getMutations() const &;
  54. ShadowViewMutationList getMutations() &&;
  55. /*
  56. * Returns telemetry associated with this transaction.
  57. */
  58. MountingTelemetry const &getTelemetry() const;
  59. /*
  60. * Returns the id of the surface that the transaction belongs to.
  61. */
  62. SurfaceId getSurfaceId() const;
  63. /*
  64. * Returns a sequential number of the particular transaction.
  65. */
  66. Number getNumber() const;
  67. private:
  68. SurfaceId surfaceId_;
  69. Number number_;
  70. ShadowViewMutationList mutations_;
  71. MountingTelemetry telemetry_;
  72. };
  73. } // namespace react
  74. } // namespace facebook