How to use the @wordpress/data.withDispatch 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 htmlburger / carbon-fields / packages / blocks / fields / index.js View on Github external
/**
 * Carbon Fields dependencies.
 */
import { withValidation } from '@carbon-fields/core';

/**
 * Internal dependencies.
 */
import withConditionalLogic from '../hocs/with-conditional-logic';

/**
 * Connects every field to the store.
 */
addFilter( 'carbon-fields.field-edit.block', 'carbon-fields/blocks', compose(
	withConditionalLogic,
	withDispatch( ( dispatch ) => {
		const { lockPostSaving, unlockPostSaving } = dispatch( 'core/editor' );

		return {
			lockSaving: lockPostSaving,
			unlockSaving: unlockPostSaving
		};
	} ),
	withValidation
) );

/**
 * Internal dependencies.
 */
import './association';
import './complex';
import './date';
github Automattic / sensei / assets / data-port / export / index.js View on Github external
import { ExportPage } from './export-page';
import registerExportStore, { EXPORT_STORE } from './store';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

registerExportStore();

export default compose(
	withSelect( ( select ) => {
		return {
			job: select( EXPORT_STORE ).getJob(),
			error: select( EXPORT_STORE ).getError(),
		};
	} ),
	withDispatch( ( dispatch ) => {
		const { start, cancel, reset } = dispatch( EXPORT_STORE );
		return { start, cancel, reset };
	} )
)( ExportPage );
github youknowriad / dropit / scripts / sidebar / components / photo / index.js View on Github external
label={__("Add photo", "dropit")}
            />
          
        )}
      
    );
  }
}

export default compose(
  withSelect(select => ({
    featuredImageId: select("core/editor").getEditedPostAttribute(
      "featured_media"
    )
  })),
  withDispatch(dispatch => ({
    insertBlock: dispatch("core/editor").insertBlock,
    updateFeaturedImage(imageId) {
      dispatch("core/editor").editPost({ featured_media: imageId });
    }
  }))
)(Photo);
github Automattic / wp-calypso / client / gutenberg / editor / edit-post / components / sidebar / featured-image / index.js View on Github external
);
}

const applyWithSelect = withSelect( select => {
	const { getEditedPostAttribute } = select( 'core/editor' );
	const { getPostType } = select( 'core' );
	const { isEditorPanelEnabled, isEditorPanelOpened } = select( 'core/edit-post' );

	return {
		postType: getPostType( getEditedPostAttribute( 'type' ) ),
		isEnabled: isEditorPanelEnabled( PANEL_NAME ),
		isOpened: isEditorPanelOpened( PANEL_NAME ),
	};
} );

const applyWithDispatch = withDispatch( dispatch => {
	const { toggleEditorPanelOpened } = dispatch( 'core/edit-post' );

	return {
		onTogglePanel: partial( toggleEditorPanelOpened, PANEL_NAME ),
	};
} );

export default compose(
	applyWithSelect,
	applyWithDispatch
)( FeaturedImage );
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / post-taxonomies / taxonomy-panel.js View on Github external
export default compose(
	withSelect( ( select, ownProps ) => {
		const slug = get( ownProps.taxonomy, [ 'slug' ] );
		const panelName = slug ? `taxonomy-panel-${ slug }` : '';
		return {
			panelName,
			isEnabled: slug ?
				select( 'core/edit-post' ).isEditorPanelEnabled( panelName ) :
				false,
			isOpened: slug ?
				select( 'core/edit-post' ).isEditorPanelOpened( panelName ) :
				false,
		};
	} ),
	withDispatch( ( dispatch, ownProps ) => ( {
		onTogglePanel: () => {
			dispatch( 'core/edit-post' ).toggleEditorPanelOpened( ownProps.panelName );
		},
	} ) ),
)( TaxonomyPanel );
github front / gutenberg-js / src / js / gutenberg-overrides / @wordpress / editor / build-module / components / inserter / menu.js View on Github external
} = select('core/editor');
    const {
      getChildBlockNames,
    } = select('core/blocks');

    const rootBlockName = getBlockName(rootClientId);

    return {
      selectedBlock: getSelectedBlock(),
      rootChildBlocks: getChildBlockNames(rootBlockName),
      title: getEditedPostAttribute('title'),
      items: getInserterItems(rootClientId),
      rootClientId,
    };
  }),
  withDispatch((dispatch, ownProps) => {
    const {
      __experimentalFetchReusableBlocks: fetchReusableBlocks,
      showInsertionPoint,
      hideInsertionPoint,
    } = dispatch('core/editor');

    return {
      fetchReusableBlocks,
      showInsertionPoint,
      hideInsertionPoint,
      onSelect (item) {
        const {
          replaceBlocks,
          insertBlock,
        } = dispatch('core/editor');
        const { selectedBlock, index, rootClientId } = ownProps;
github Charitable / Charitable / src / blocks / campaign-progress-bar / inspector.js View on Github external
min={ 8 }
					max={ 60 }
					value={ progressBarHeight }
				/>
			
		
	);
}

const applyWithSelect = withSelect( (select) => {
	return {
		goal: select( 'core/editor' ).getEditedPostAttribute( 'goal' )
	}
} );

const applyWithDispatch = withDispatch( (dispatch) => {
	return {
		onGoalChange: (value) => {
			dispatch( 'core/editor' ).editPost( { goal: value } )
		}
	}
} );

export const Inspector = compose(
	applyWithSelect,
	applyWithDispatch
)( InspectorBase );
github WordPress / gutenberg / packages / edit-post / src / components / sidebar / plugin-sidebar / index.js View on Github external
icon: ownProps.icon || context.icon,
			sidebarName: `${ context.name }/${ ownProps.name }`,
		};
	} ),
	withSelect( ( select, { sidebarName } ) => {
		const {
			getActiveGeneralSidebarName,
			isPluginItemPinned,
		} = select( 'core/edit-post' );

		return {
			isActive: getActiveGeneralSidebarName() === sidebarName,
			isPinned: isPluginItemPinned( sidebarName ),
		};
	} ),
	withDispatch( ( dispatch, { isActive, sidebarName } ) => {
		const {
			closeGeneralSidebar,
			openGeneralSidebar,
			togglePinnedPluginItem,
		} = dispatch( 'core/edit-post' );

		return {
			togglePin() {
				togglePinnedPluginItem( sidebarName );
			},
			toggleSidebar() {
				if ( isActive ) {
					closeGeneralSidebar();
				} else {
					openGeneralSidebar( sidebarName );
				}
github Automattic / wp-calypso / client / gutenberg / editor / edit-post / components / header / index.js View on Github external
);
}

export default compose(
	withSelect( select => ( {
		hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
		hasBlockSelection: !! select( 'core/editor' ).getBlockSelectionStart(),
		isEditorSidebarOpened: select( 'core/edit-post' ).isEditorSidebarOpened(),
		isPublishSidebarOpened: select( 'core/edit-post' ).isPublishSidebarOpened(),
		isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
	} ) ),
	withDispatch( ( dispatch, { hasBlockSelection } ) => {
		const { openGeneralSidebar, closeGeneralSidebar } = dispatch( 'core/edit-post' );
		const sidebarToOpen = hasBlockSelection ? 'edit-post/block' : 'edit-post/document';

		return {
			openGeneralSidebar: () => openGeneralSidebar( sidebarToOpen ),
			closeGeneralSidebar: closeGeneralSidebar,
		};
	} )
)( Header );
github WordPress / gutenberg / packages / block-editor / src / components / default-block-appender / index.native.js View on Github external
}

export default compose(
	withSelect( ( select, ownProps ) => {
		const { getBlockCount, getSettings, getTemplateLock } = select( 'core/block-editor' );

		const isEmpty = ! getBlockCount( ownProps.rootClientId );
		const { bodyPlaceholder } = getSettings();

		return {
			isVisible: isEmpty,
			isLocked: !! getTemplateLock( ownProps.rootClientId ),
			placeholder: bodyPlaceholder,
		};
	} ),
	withDispatch( ( dispatch, ownProps ) => {
		const {
			insertDefaultBlock,
			startTyping,
		} = dispatch( 'core/block-editor' );

		return {
			onAppend() {
				const { rootClientId } = ownProps;

				insertDefaultBlock( undefined, rootClientId );
				startTyping();
			},
		};
	} ),
)( DefaultBlockAppender );