{
  "version": 3,
  "sources": ["../../src/storeObservation/shallowCompareFragmentReferences.ts"],
  "sourcesContent": ["/**\n * Modified from https://github.com/facebook/react/blob/201af81b0168cabea3cc07cd8201378a4fec4aaf/packages/shared/shallowEqual.js\n * Copying is the suggested way, as mentioned here https://github.com/facebook/react/issues/16919\n */\n\n/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found at\n * https://github.com/facebook/react/blob/201af81b0168cabea3cc07cd8201378a4fec4aaf/LICENSE\n */\n\nimport invariant from \"invariant\";\n\n/**\n * A custom React.memo() comparator function factory that can be used with\n * components that use `useFragment` on a GraphQL type that implements the\n * `Node` interface, in which case only the `id` value needs to be equal to\n * avoid a re-render.\n *\n * @todo\n *   Support arrays with fragment references\n *\n * @param fragmentReferenceProps\n *   The props that refer to fragment references and should only be compared by\n *   their [Node] ids.\n *\n * @returns\n *   A comparator with parameters typed such that TS can verify the component\n *   passed to React.memo() has props that match.\n */\nexport function shallowCompareFragmentReferences<\n  K extends string,\n  ComparatorParam extends { [key in K]: { \" $fragmentSpreads\": unknown } },\n>(\n  ...fragmentReferenceProps: K[]\n): (prevProps: ComparatorParam, nextProps: ComparatorParam) => boolean {\n  return (prevProps, nextProps) => {\n    if (Object.is(prevProps, nextProps)) {\n      return true;\n    }\n\n    const keysPrev = Object.keys(prevProps);\n    const keysNext = Object.keys(nextProps);\n\n    if (keysPrev.length !== keysNext.length) {\n      return false;\n    }\n\n    for (let i = 0; i < keysPrev.length; i++) {\n      const checkKey = keysPrev[i] as K;\n      if (\n        !Object.prototype.hasOwnProperty.call(nextProps, checkKey) ||\n        fragmentReferenceProps.includes(checkKey)\n          ? !idsEqual(\n              prevProps[checkKey] as { id?: unknown },\n              nextProps[checkKey] as { id?: unknown },\n            )\n          : !Object.is(prevProps[checkKey], nextProps[checkKey])\n      ) {\n        return false;\n      }\n    }\n\n    return true;\n  };\n}\n\nfunction idsEqual(objA: { id?: unknown }, objB: { id?: unknown }) {\n  invariant(\n    objA.id && objB.id,\n    \"Expected both fragment reference objects to have an id field\",\n  );\n  return objA.id === objB.id;\n}\n"],
  "mappings": ";AAYA,OAAO,eAAe;AAmBf,SAAS,oCAIX,wBACkE;AACrE,SAAO,CAAC,WAAW,cAAc;AAC/B,QAAI,OAAO,GAAG,WAAW,SAAS,GAAG;AACnC,aAAO;AAAA,IACT;AAEA,UAAM,WAAW,OAAO,KAAK,SAAS;AACtC,UAAM,WAAW,OAAO,KAAK,SAAS;AAEtC,QAAI,SAAS,WAAW,SAAS,QAAQ;AACvC,aAAO;AAAA,IACT;AAEA,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;AACxC,YAAM,WAAW,SAAS,CAAC;AAC3B,UACE,CAAC,OAAO,UAAU,eAAe,KAAK,WAAW,QAAQ,KACzD,uBAAuB,SAAS,QAAQ,IACpC,CAAC;AAAA,QACC,UAAU,QAAQ;AAAA,QAClB,UAAU,QAAQ;AAAA,MACpB,IACA,CAAC,OAAO,GAAG,UAAU,QAAQ,GAAG,UAAU,QAAQ,CAAC,GACvD;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,SAAS,MAAwB,MAAwB;AAChE;AAAA,IACE,KAAK,MAAM,KAAK;AAAA,IAChB;AAAA,EACF;AACA,SAAO,KAAK,OAAO,KAAK;AAC1B;",
  "names": []
}
