1 | {"version":3,"sources":["../../src/util/fromRenderProp.js"],"names":["React","cache","Map","filterProps","props","blacklist","Object","entries","reduce","r","k","v","includes","fromRenderProp","elementType","customProps","isComposite","uniqueCustomProps","Array","from","Set","sort","key","join","has","Component","createElement","displayName","set","get"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB,C,CAEA;;AACA,MAAMC,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA,OAAO,MAAMC,WAAW,GAAG,CAACC,KAAK,GAAG,EAAT,EAAaC,SAAS,GAAG,EAAzB,KACvBC,MAAM,CAACC,OAAP,CAAeH,KAAf,EAAsBI,MAAtB,CAA6B,CAACC,CAAD,EAAI,CAACC,CAAD,EAAIC,CAAJ,CAAJ,KAAe;AACxC,MAAI,CAACN,SAAS,CAACO,QAAV,CAAmBF,CAAnB,CAAL,EAA4B;AACxBD,IAAAA,CAAC,CAACC,CAAD,CAAD,GAAOC,CAAP;AACH;;AACD,SAAOF,CAAP;AACH,CALD,EAKG,EALH,CADG;;AAQP,MAAMI,cAAc,GAAG,CAACC,WAAD,EAAcC,WAAW,GAAG,EAA5B,KAAmC;AACtD,QAAMC,WAAW,GAAG,OAAOF,WAAP,KAAuB,UAA3C,CADsD,CAGtD;;AACA,MAAIE,WAAJ,EAAiB;AACb,WAAOF,WAAP;AACH,GANqD,CAQtD;;;AACA,QAAMG,iBAAiB,GAAGC,KAAK,CAACC,IAAN,CAAW,IAAIC,GAAJ,CAAQ,CAAC,GAAGL,WAAJ,EAAiBM,IAAjB,EAAR,CAAX,CAA1B,CATsD,CAWtD;;AACA,QAAMC,GAAG,GAAI,GAAER,WAAY,KAAIG,iBAAiB,CAACM,IAAlB,CAAuB,GAAvB,CAA4B,EAA3D,CAZsD,CActD;AACA;;AACA,MAAI,CAACtB,KAAK,CAACuB,GAAN,CAAUF,GAAV,CAAL,EAAqB;AACjB;AACA;AACA,UAAMG,SAAS,GAAGrB,KAAK,IACnBJ,KAAK,CAAC0B,aAAN,CACIZ,WADJ,EAEIX,WAAW,CAACC,KAAD,EAAQa,iBAAR,CAFf,CADJ;;AAMAQ,IAAAA,SAAS,CAACE,WAAV,GAAyB,kBAAiBb,WAAY,GAAtD;AACAb,IAAAA,KAAK,CAAC2B,GAAN,CAAUN,GAAV,EAAeG,SAAf;AACH;;AAED,SAAOxB,KAAK,CAAC4B,GAAN,CAAUP,GAAV,CAAP;AACH,CA9BD;;AAgCA,eAAeT,cAAf","sourcesContent":["import React from 'react';\n\n// memoization cache\nconst cache = new Map();\n\nexport const filterProps = (props = {}, blacklist = []) =>\n Object.entries(props).reduce((r, [k, v]) => {\n if (!blacklist.includes(k)) {\n r[k] = v;\n }\n return r;\n }, {});\n\nconst fromRenderProp = (elementType, customProps = []) => {\n const isComposite = typeof elementType === 'function';\n\n // if `elementType` is a function, it's already a component\n if (isComposite) {\n return elementType;\n }\n\n // sort and de-dupe `customProps`\n const uniqueCustomProps = Array.from(new Set([...customProps].sort()));\n\n // hash arguments for memoization\n const key = `${elementType}//${uniqueCustomProps.join(',')}`;\n\n // only create a new component if not cached\n // otherwise React will unmount on every render\n if (!cache.has(key)) {\n // create an SFC that renders a node of type `elementType`\n // and filter any props that shouldn't be written to the DOM\n const Component = props =>\n React.createElement(\n elementType,\n filterProps(props, uniqueCustomProps)\n );\n\n Component.displayName = `fromRenderProp(${elementType})`;\n cache.set(key, Component);\n }\n\n return cache.get(key);\n};\n\nexport default fromRenderProp;\n"],"file":"fromRenderProp.js"} |