@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
8 lines (7 loc) • 1.64 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/entity-provider.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { EntityContext } from './entity-context';\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst parent = useContext( EntityContext );\n\tconst childContext = useMemo(\n\t\t() => ( {\n\t\t\t...parent,\n\t\t\t[ kind ]: {\n\t\t\t\t...parent?.[ kind ],\n\t\t\t\t[ name ]: id,\n\t\t\t},\n\t\t} ),\n\t\t[ parent, kind, name, id ]\n\t);\n\treturn (\n\t\t<EntityContext.Provider value={ childContext }>\n\t\t\t{ children }\n\t\t</EntityContext.Provider>\n\t);\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAoC;AAKpC,4BAA8B;AA4B5B;AAba,SAAR,eAAiC,EAAE,MAAM,MAAM,MAAM,IAAI,SAAS,GAAI;AAC5E,QAAM,aAAS,2BAAY,mCAAc;AACzC,QAAM,mBAAe;AAAA,IACpB,OAAQ;AAAA,MACP,GAAG;AAAA,MACH,CAAE,IAAK,GAAG;AAAA,QACT,GAAG,SAAU,IAAK;AAAA,QAClB,CAAE,IAAK,GAAG;AAAA,MACX;AAAA,IACD;AAAA,IACA,CAAE,QAAQ,MAAM,MAAM,EAAG;AAAA,EAC1B;AACA,SACC,4CAAC,oCAAc,UAAd,EAAuB,OAAQ,cAC7B,UACH;AAEF;",
"names": []
}