Skip to content

Commit

Permalink
Ensure stores exist in "resolve"
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Mar 14, 2024
1 parent 813274c commit 9395e19
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/interactivity/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { VNode, Context, RefObject } from 'preact';
/**
* Internal dependencies
*/
import { stores } from './store';
import { store, stores, universalUnlock } from './store';
interface DirectiveEntry {
value: string | Object;
namespace: string;
Expand Down Expand Up @@ -259,8 +259,14 @@ export const directive = (

// Resolve the path to some property of the store object.
const resolve = ( path, namespace ) => {
let resolvedStore = stores.get( namespace );
if ( typeof resolvedStore === 'undefined' ) {
resolvedStore = store( namespace, undefined, {
lock: universalUnlock,
} );
}
let current = {
...stores.get( namespace ),
...resolvedStore,
context: getScope().context[ namespace ],
};
path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );
Expand Down

0 comments on commit 9395e19

Please sign in to comment.