Skip to content

Commit

Permalink
Quality: Replace deprecated registerStore (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano authored Mar 8, 2024
1 parent 16fbade commit 2140e5a
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions src/store.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
/**
* WordPress dependencies
*/
import { registerStore } from '@wordpress/data';
import { createReduxStore, register } from '@wordpress/data';

const DEFAULT_STATE = {
isResponsive: false,
};

const reducer = ( state = DEFAULT_STATE, action ) => {
if ( action.type === 'UPDATE_IS_RESPONSIVE' ) {
return {
...state,
isResponsive: ! state.isResponsive,
};
}

return state;
};

const actions = {
setIsResponsive( value ) {
return {
type: 'UPDATE_IS_RESPONSIVE',
value,
};
const store = createReduxStore( 'flexible-spacer-block', {
reducer: ( state = DEFAULT_STATE, action ) => {
if ( action.type === 'UPDATE_IS_RESPONSIVE' ) {
return {
...state,
isResponsive: ! state.isResponsive,
};
}
return state;
},
};

const selectors = {
getIsResponsive( state ) {
return state.isResponsive;
selectors: {
getIsResponsive( state ) {
return state.isResponsive;
},
},
actions: {
setIsResponsive( value ) {
return {
type: 'UPDATE_IS_RESPONSIVE',
value,
};
},
},
};

registerStore( 'flexible-spacer-block', {
reducer,
actions,
selectors,
} );

register( store );

0 comments on commit 2140e5a

Please sign in to comment.