1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and 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. 
    
  8. const instanceCache = new Map();
    
  9. const instanceProps = new Map();
    
  10. 
    
  11. export function precacheFiberNode(hostInst, tag) {
    
  12.   instanceCache.set(tag, hostInst);
    
  13. }
    
  14. 
    
  15. export function uncacheFiberNode(tag) {
    
  16.   instanceCache.delete(tag);
    
  17.   instanceProps.delete(tag);
    
  18. }
    
  19. 
    
  20. function getInstanceFromTag(tag) {
    
  21.   return instanceCache.get(tag) || null;
    
  22. }
    
  23. 
    
  24. function getTagFromInstance(inst) {
    
  25.   let nativeInstance = inst.stateNode;
    
  26.   let tag = nativeInstance._nativeTag;
    
  27.   if (tag === undefined && nativeInstance.canonical != null) {
    
  28.     // For compatibility with Fabric
    
  29.     tag = nativeInstance.canonical.nativeTag;
    
  30.     nativeInstance = nativeInstance.canonical.publicInstance;
    
  31.   }
    
  32. 
    
  33.   if (!tag) {
    
  34.     throw new Error('All native instances should have a tag.');
    
  35.   }
    
  36. 
    
  37.   return nativeInstance;
    
  38. }
    
  39. 
    
  40. export {
    
  41.   getInstanceFromTag as getClosestInstanceFromNode,
    
  42.   getInstanceFromTag as getInstanceFromNode,
    
  43.   getTagFromInstance as getNodeFromInstance,
    
  44. };
    
  45. 
    
  46. export function getFiberCurrentPropsFromNode(stateNode) {
    
  47.   return instanceProps.get(stateNode._nativeTag) || null;
    
  48. }
    
  49. 
    
  50. export function updateFiberProps(tag, props) {
    
  51.   instanceProps.set(tag, props);
    
  52. }