BlobRegistry.js 689 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. * @flow strict
  8. * @format
  9. */
  10. const registry: {[key: string]: number, ...} = {};
  11. const register = (id: string) => {
  12. if (registry[id]) {
  13. registry[id]++;
  14. } else {
  15. registry[id] = 1;
  16. }
  17. };
  18. const unregister = (id: string) => {
  19. if (registry[id]) {
  20. registry[id]--;
  21. if (registry[id] <= 0) {
  22. delete registry[id];
  23. }
  24. }
  25. };
  26. const has = (id: string): number | boolean => {
  27. return registry[id] && registry[id] > 0;
  28. };
  29. module.exports = {
  30. register,
  31. unregister,
  32. has,
  33. };