Skip to content

Commit 3dc8989

Browse files
committed
Add options.invokeFunctions to evaluate
1 parent 0740acc commit 3dc8989

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/interactivity/src/hooks.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ interface DirectiveOptions {
9191
}
9292

9393
export interface Evaluate {
94-
( entry: DirectiveEntry, ...args: any[] ): any;
94+
(
95+
entry: DirectiveEntry,
96+
options: {
97+
invokeFunctions: boolean;
98+
}
99+
): any;
95100
}
96101

97102
interface GetEvaluate {
@@ -231,7 +236,7 @@ const resolve = ( path: string, namespace: string ) => {
231236
// Generate the evaluate function.
232237
export const getEvaluate: GetEvaluate =
233238
( { scope } ) =>
234-
( entry, ...args ) => {
239+
( entry, options ) => {
235240
let { value: path, namespace } = entry;
236241
if ( typeof path !== 'string' ) {
237242
throw new Error( 'The `value` prop should be a string path' );
@@ -241,9 +246,10 @@ export const getEvaluate: GetEvaluate =
241246
path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
242247
setScope( scope );
243248
const value = resolve( path, namespace );
244-
const result = typeof value === 'function' ? value( ...args ) : value;
249+
const isFunction = typeof value === 'function';
250+
const result = options?.invokeFunctions && isFunction ? value() : value;
245251
resetScope();
246-
return hasNegationOperator ? ! result : result;
252+
return hasNegationOperator && ! isFunction ? ! result : result;
247253
};
248254

249255
// Separate directives by priority. The resulting array contains objects

0 commit comments

Comments
 (0)