From 06c644a4a63aa393d3a6b5094d82116a606e2540 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Wed, 8 May 2024 00:53:39 +0530 Subject: [PATCH] Added comments for directive parsing --- packages/interactivity/src/vdom.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/interactivity/src/vdom.ts b/packages/interactivity/src/vdom.ts index 9e6221bb871f4f..07956d0e942719 100644 --- a/packages/interactivity/src/vdom.ts +++ b/packages/interactivity/src/vdom.ts @@ -116,8 +116,11 @@ export function toVdom( root ) { } if ( directives.length ) { + // Reduce the directives array to build the __directives object. props.__directives = directives.reduce( + // The reducer function accumulates the __directives object. ( obj, [ name, ns, value ] ) => { + // Check if the directive name matches the expected format. const directiveMatch = directiveParser.exec( name ); if ( directiveMatch === null ) { if ( @@ -131,9 +134,11 @@ export function toVdom( root ) { } return obj; } - const prefix = directiveMatch[ 1 ] || ''; - const suffix = directiveMatch[ 2 ] || 'default'; + // Splitting the directive name into prefix and suffix. + const prefix = directiveMatch[ 1 ] || ''; // The prefix part of the directive name. + const suffix = directiveMatch[ 2 ] || 'default'; // The suffix part of the directive name, defaulting to 'default' if not present. + // Creating or updating the array for the specific prefix in the directives object. obj[ prefix ] = obj[ prefix ] || []; obj[ prefix ].push( { namespace: ns ?? currentNamespace(),