♻️ Implement new store-hooks accessor logic

This commit is contained in:
Philipp Stracker 2025-01-21 15:37:59 +01:00
parent 4de4e05829
commit 13947a5d01
No known key found for this signature in database
2 changed files with 7 additions and 20 deletions

View file

@ -15,7 +15,6 @@ import { STORE_NAME } from './constants';
const useHooks = () => { const useHooks = () => {
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME ); const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
const { persist } = useDispatch( STORE_NAME ); const { persist } = useDispatch( STORE_NAME );
// Read-only flags and derived state. // Read-only flags and derived state.

View file

@ -6,32 +6,20 @@
* *
* @file * @file
*/ */
import { useSelect, useDispatch } from '@wordpress/data'; import { useDispatch } from '@wordpress/data';
import { STORE_NAME } from './constants'; import { STORE_NAME } from './constants';
import { createHooksForStore } from '../utils';
const useTransient = ( key ) =>
useSelect(
( select ) => select( STORE_NAME ).transientData()?.[ key ],
[ key ]
);
const usePersistent = ( key ) =>
useSelect(
( select ) => select( STORE_NAME ).persistentData()?.[ key ],
[ key ]
);
const useHooks = () => { const useHooks = () => {
const { persist, setSettings } = useDispatch( STORE_NAME ); const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
const { persist } = useDispatch( STORE_NAME );
// Read-only flags and derived state. // Read-only flags and derived state.
const isReady = useTransient( 'isReady' ); const [ isReady ] = useTransient( 'isReady' );
// Persistent accessors. // Persistent accessors.
const settings = useSelect( const [ settings, setSettings ] = usePersistent( 'settings' );
( select ) => select( STORE_NAME ).persistentData(),
[]
);
return { return {
persist, persist,