From f512ea769abe1cbc54385567cf1d028de0b9712e Mon Sep 17 00:00:00 2001 From: Alexandre Lara Date: Thu, 26 Oct 2023 22:59:57 -0300 Subject: [PATCH] Add `data-wc-init` directive to Interactivity API (https://github.com/woocommerce/woocommerce-blocks/pull/11458) --- .../assets/js/interactivity/directives.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/woocommerce-blocks/assets/js/interactivity/directives.js b/plugins/woocommerce-blocks/assets/js/interactivity/directives.js index 96bd2320d61..b747fa0cfdf 100644 --- a/plugins/woocommerce-blocks/assets/js/interactivity/directives.js +++ b/plugins/woocommerce-blocks/assets/js/interactivity/directives.js @@ -74,6 +74,16 @@ export default () => { } ); + // data-wc-init--[name] + directive( 'init', ( { directives: { init }, context, evaluate } ) => { + const contextValue = useContext( context ); + Object.values( init ).forEach( ( path ) => { + useEffect( () => { + return evaluate( path, { context: contextValue } ); + }, [] ); + } ); + } ); + // data-wc-on--[event] directive( 'on', ( { directives: { on }, element, evaluate, context } ) => { const contextValue = useContext( context );