Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality: Replace deprecated registerStore #56

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Loading