Skip to content

Commit

Permalink
Move warn to same resolve function
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed May 9, 2024
1 parent 8ba40ca commit 7a26116
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/interactivity/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export const directive = (

// Resolve the path to some property of the store object.
const resolve = ( path, namespace ) => {
if ( ! namespace ) {
warn(
`The "namespace" cannot be "{}", "null" or an emtpy string. Path: ${ path }`
);
return;
}
let resolvedStore = stores.get( namespace );
if ( typeof resolvedStore === 'undefined' ) {
resolvedStore = store( namespace, undefined, {
Expand All @@ -272,8 +278,13 @@ const resolve = ( path, namespace ) => {
context: getScope().context[ namespace ],
};
try {
// TODO: Support lazy/dynamically initialized stores
return path.split( '.' ).reduce( ( acc, key ) => acc[ key ], current );
} catch ( e ) {}
} catch ( e ) {
warn(
`The path "${ path }" could not be resolved in the "${ namespace }" store.`
);
}
};

// Generate the evaluate function.
Expand All @@ -284,12 +295,6 @@ export const getEvaluate: GetEvaluate =
if ( typeof path !== 'string' ) {
throw new Error( 'The `value` prop should be a string path' );
}
if ( ! namespace ) {
// TODO: Support lazy/dynamically initialized stores
warn(
`The "namespace" cannot be "{}", "null" or an emtpy string. Path: ${ path }`
);
}
// If path starts with !, remove it and save a flag.
const hasNegationOperator =
path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
Expand Down

0 comments on commit 7a26116

Please sign in to comment.