How to use the @wordpress/data.registerGenericStore function in @wordpress/data

To help you get started, we’ve selected a few @wordpress/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github insideout10 / wordlift-plugin / src / src / js / src / block-editor / stores / index.js View on Github external
import saga from "./sagas";
import { editorSelectionChanged } from "../../Edit/actions";
import { setValue } from "../../Edit/components/AddEntity/actions";
import { WORDLIFT_STORE } from "../../common/constants";

const initialState = { entities: Map() };
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
  combineReducers({ entities, annotationFilter, visibilityFilter, blockEditor, createEntityForm, relatedPosts }),
  initialState,
  applyMiddleware(sagaMiddleware, logger)
);
sagaMiddleware.run(saga);

// Register the store with WordPress.
registerGenericStore(WORDLIFT_STORE, {
  getSelectors() {
    return {
      getAnnotationFilter: (...args) => getAnnotationFilter(store.getState(), ...args),
      getEditor: (...args) => getEditor(store.getState(), ...args),
      getEntities: (...args) => getEntities(store.getState(), ...args),
      getSelectedEntities: (...args) => getSelectedEntities(store.getState(), ...args),
      getBlockEditor: (...args) => getBlockEditor(store.getState(), ...args),
      getBlockEditorFormat: (...args) => getBlockEditorFormat(store.getState(), ...args)
    };
  },
  getActions() {
    return {
      editorSelectionChanged: args => store.dispatch(editorSelectionChanged(args)),
      requestAnalysis: (...args) => store.dispatch(requestAnalysis(...args)),
      // Called when the selection changes in editor.
      setValue: args => store.dispatch(setValue(args)),
github pods-framework / pods / ui / js / dfv / src / admin / edit-pod / store / store.js View on Github external
const mappedActions = Object.keys( actions ).reduce( ( acc, actionKey ) => {
		acc[ actionKey ] = ( ...args ) => reduxStore.dispatch( actions[ actionKey ]( ...args ) );
		return acc;
	}, {} );

	const genericStore = {
		getSelectors() {
			return mappedSelectors;
		},
		getActions() {
			return mappedActions;
		},
		subscribe: reduxStore.subscribe,
	};

	registerGenericStore( STORE_KEY_EDIT_POD, genericStore );
};