UNPKG

@wordpress/notices

Version:
8 lines (7 loc) 1.76 kB
{ "version": 3, "sources": ["../../src/store/reducer.ts"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { keyedReducer } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Notice, ReducerAction } from './types';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nconst notices = keyedReducer< Array< Notice >, ReducerAction >( 'context' )( (\n\tstate = [],\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\n\t\tdefault:\n\t\t\treturn state;\n\t}\n} );\n\nexport default notices;\n"], "mappings": ";AAGA,SAAS,oBAAoB;AAgB7B,IAAM,UAAU,aAAgD,SAAU,EAAG,CAC5E,QAAQ,CAAC,GACT,WACI;AACJ,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AAEJ,aAAO;AAAA,QACN,GAAG,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,OAAO,EAAG;AAAA,QACvD,OAAO;AAAA,MACR;AAAA,IAED,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,EAAG;AAAA,IAErD,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,CAAE,OAAO,IAAI,SAAU,EAAG,CAAE;AAAA,IAEhE,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,OAAO,UAAW;AAAA,IAEjE;AACC,aAAO;AAAA,EACT;AACD,CAAE;AAEF,IAAO,kBAAQ;", "names": [] }