UNPKG

@wordpress/notices

Version:
8 lines (7 loc) 1.64 kB
{ "version": 3, "sources": ["../../src/store/selectors.ts"], "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\nimport type { Notice } from './types';\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n */\nconst DEFAULT_NOTICES: Array< Notice > = [];\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param state Notices state.\n * @param context Optional grouping context.\n *\n * @example\n *\n *```js\n * import { useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * return (\n * <ul>\n * { notices.map( ( notice ) => (\n * <li key={ notice.ID }>{ notice.content }</li>\n * ) ) }\n * </ul>\n * )\n * };\n *```\n *\n * @return Array of notices.\n */\nexport function getNotices(\n\tstate: Record< string, Array< Notice > >,\n\tcontext: string = DEFAULT_CONTEXT\n) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"], "mappings": ";AAGA,SAAS,uBAAuB;AAWhC,IAAM,kBAAmC,CAAC;AA6BnC,SAAS,WACf,OACA,UAAkB,iBACjB;AACD,SAAO,MAAO,OAAQ,KAAK;AAC5B;", "names": [] }