From b9785d17055c0f60a7eee56e3f6a5023129f70b5 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Mon, 17 Feb 2025 13:43:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add=20simpl?= =?UTF-8?q?e=20filter-callback=20for=20dumpStore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ppcp-settings/resources/js/data/debug.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-settings/resources/js/data/debug.js b/modules/ppcp-settings/resources/js/data/debug.js index 66530d7ec..286285892 100644 --- a/modules/ppcp-settings/resources/js/data/debug.js +++ b/modules/ppcp-settings/resources/js/data/debug.js @@ -26,7 +26,7 @@ export const addDebugTools = ( context, modules ) => { const debugApi = ( window.ppcpDebugger = window.ppcpDebugger || {} ); // Dump the current state of all our Redux stores. - debugApi.dumpStore = async () => { + debugApi.dumpStore = async ( cbFilter = null ) => { /* eslint-disable no-console */ if ( ! console?.groupCollapsed ) { console.error( 'console.groupCollapsed is not supported.' ); @@ -39,11 +39,19 @@ export const addDebugTools = ( context, modules ) => { console.group( `[STORE] ${ storeSelector }` ); const dumpStore = ( selector ) => { - const contents = wp.data.select( storeName )[ selector ](); + let contents = wp.data.select( storeName )[ selector ](); - console.groupCollapsed( `.${ selector }()` ); - console.table( contents ); - console.groupEnd(); + if ( cbFilter ) { + contents = cbFilter( contents, selector, storeName ); + + if ( undefined !== contents && null !== contents ) { + console.log( `.${ selector }() [filtered]`, contents ); + } + } else { + console.groupCollapsed( `.${ selector }()` ); + console.table( contents ); + console.groupEnd(); + } }; Object.keys( module.selectors ).forEach( dumpStore );