text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.createReactionCleanupTrackingUsingFinalizationRegister = void 0;
  var reactionCleanupTrackingCommon_1 = require("./reactionCleanupTrackingCommon");
  /**
   * FinalizationRegistry-based uncommitted reaction cleanup
   */
  function createReactionCleanupTrackingUsingFinalizationRegister(FinalizationRegistry) {
      var cleanupTokenToReactionTrackingMap = new Map();
      var globalCleanupTokensCounter = 1;
      var registry = new FinalizationRegistry(function cleanupFunction(token) {
          var trackedReaction = cleanupTokenToReactionTrackingMap.get(token);
          if (trackedReaction) {
              trackedReaction.reaction.dispose();
              cleanupTokenToReactionTrackingMap.delete(token);
          }
      });
      return {
          addReactionToTrack: function (reactionTrackingRef, reaction, objectRetainedByReact) {
              var token = globalCleanupTokensCounter++;
              registry.register(objectRetainedByReact, token, reactionTrackingRef);
              reactionTrackingRef.current = reactionCleanupTrackingCommon_1.createTrackingData(reaction);
              reactionTrackingRef.current.finalizationRegistryCleanupToken = token;
              cleanupTokenToReactionTrackingMap.set(token, reactionTrackingRef.current);
              return reactionTrackingRef.current;
          },
          recordReactionAsCommitted: function (reactionRef) {
              registry.unregister(reactionRef);
              if (reactionRef.current && reactionRef.current.finalizationRegistryCleanupToken) {
                  cleanupTokenToReactionTrackingMap.delete(reactionRef.current.finalizationRegistryCleanupToken);
              }
          },
          forceCleanupTimerToRunNowForTests: function () {
              // When FinalizationRegistry in use, this this is no-op
          },
          resetCleanupScheduleForTests: function () {
              // When FinalizationRegistry in use, this this is no-op
          }
      };
  }
  exports.createReactionCleanupTrackingUsingFinalizationRegister = createReactionCleanupTrackingUsingFinalizationRegister;
  //# sourceMappingURL=createReactionCleanupTrackingUsingFinalizationRegister.js.map