Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
{"version":3,"file":"getSharedResource.js","sourceRoot":"","sources":["../src/getSharedResource.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,MAAM,uCAAuC,CAAC;AAEhF,MAAM,YAAY,GAAG,GAAG,EAAE;IACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,4DAA4D;IAC5F,OAAO,EAAE,CAAC;AACX,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAAG,GAAmB,EAAE;IACvD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QACpC,OAAO,IAAI,CAAC;KACZ;IACD,OAAO,2BAA2B,CAAC,mCAAmC,EAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AACtG,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAG,CAAI,SAAiB,EAAE,YAAe,EAAK,EAAE;IACtE,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,OAAO,GAAG,0BAA0B,EAAyB,CAAC;IAElE,IAAI,CAAC,OAAO,EAAE;QACb,OAAO,YAAY,CAAC;KACpB;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,QAAQ,GAAG,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE;YACzD,OAAO,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7C;QACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACxB;IAED,OAAO,OAAY,CAAC;AACrB,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC","sourcesContent":["import getSingletonElementInstance from \"./util/getSingletonElementInstance.js\";\n\nconst getMetaDomEl = () => {\n\tconst el = document.createElement(\"meta\");\n\tel.setAttribute(\"name\", \"ui5-shared-resources\");\n\tel.setAttribute(\"content\", \"\"); // attribute \"content\" should be present when \"name\" is set.\n\treturn el;\n};\n\nconst getSharedResourcesInstance = (): Element | null => {\n\tif (typeof document === \"undefined\") {\n\t\treturn null;\n\t}\n\treturn getSingletonElementInstance(`meta[name=\"ui5-shared-resources\"]`, document.head, getMetaDomEl);\n};\n\n/**\n * Use this method to initialize/get resources that you would like to be shared among UI5 Web Components runtime instances.\n * The data will be accessed via a singleton \"ui5-shared-resources\" HTML element in the \"body\" element of the page.\n *\n * @public\n * @param namespace Unique ID of the resource, may contain \".\" to denote hierarchy\n * @param initialValue Object or primitive that will be used as an initial value if the resource does not exist\n * @returns {*}\n */\nconst getSharedResource = (namespace: string, initialValue: T): T => {\n\tconst parts = namespace.split(\".\");\n\tlet current = getSharedResourcesInstance() as Record;\n\n\tif (!current) {\n\t\treturn initialValue;\n\t}\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst lastPart = i === parts.length - 1;\n\t\tif (!Object.prototype.hasOwnProperty.call(current, part)) {\n\t\t\tcurrent[part] = lastPart ? initialValue : {};\n\t\t}\n\t\tcurrent = current[part];\n\t}\n\n\treturn current as T;\n};\n\nexport default getSharedResource;\n"]}