How to use the @wordpress/hooks.addAction function in @wordpress/hooks

To help you get started, we’ve selected a few @wordpress/hooks 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 WordPress / gutenberg / src / block-management / block-holder.js View on Github external
onInlineToolbarButtonPressed = ( button: number ) => {
		Keyboard.dismiss();
		switch ( button ) {
			case InlineToolbarActions.UP:
				this.props.moveBlockUp();
				break;
			case InlineToolbarActions.DOWN:
				this.props.moveBlockDown();
				break;
			case InlineToolbarActions.DELETE:
				// adding a action that will exist for as long as it takes for the block to be removed and the component unmounted
				// this acts as a flag for the code using the action to know of its existence
				addAction( 'blocks.onRemoveBlockCheckUpload', 'gutenberg-mobile/blocks', this.onRemoveBlockCheckUpload );
				this.props.removeBlock();
				break;
		}
	};
github WordPress / gutenberg / packages / components / src / higher-order / with-filters / index.js View on Github external
componentDidMount() {
				FilteredComponentRenderer.instances.push( this );

				// If there were previously no mounted instances for components
				// filtered on this hook, add the hook handler.
				if ( FilteredComponentRenderer.instances.length === 1 ) {
					addAction( 'hookRemoved', namespace, onHooksUpdated );
					addAction( 'hookAdded', namespace, onHooksUpdated );
				}
			}
github WordPress / gutenberg / packages / editor / src / components / post-locked-modal / index.js View on Github external
componentDidMount() {
		const hookName = this.getHookName();

		// Details on these events on the Heartbeat API docs
		// https://developer.wordpress.org/plugins/javascript/heartbeat-api/
		addAction( 'heartbeat.send', hookName, this.sendPostLock );
		addAction( 'heartbeat.tick', hookName, this.receivePostLock );
	}
github pento / testpress / src / services / npm-watcher / index.js View on Github external
Object.keys( cwds ).forEach( ( folderPref ) => {
		addAction( 'updated_node_and_npm', 'runNPMInstall', () => runNPMInstall( folderPref ) );

		cwds[ folderPref ] = preferences.value( 'basic', folderPref );
		if ( ! cwds[ folderPref ] ) {
			return;
		}

		const packageJson = normalize( cwds[ folderPref ] + '/package.json' );

		if ( existsSync( packageJson ) ) {
			debug( '(%s) Registering package.json watcher', folderPref );
			watch( packageJson ).on( 'change', () => {
				debug( '(%s) package.json change detected', folderPref );
				runNPMInstall( folderPref );
			 } );
		}
	} );
github pento / testpress / src / services / docker / index.js View on Github external
async function registerDockerJob() {
	debug( 'Registering job' );

	if ( 'win32' === process.platform ) {
		USING_TOOLBOX = await detectToolbox();
	}

	addAction( 'preference_saved', 'preferenceSaved', preferenceSaved, 9 );
	addAction( 'shutdown', 'shutdown', shutdown );

	startDocker();
}
github pento / testpress / src / services / grunt / index.js View on Github external
function registerGruntJob() {
	debug( 'Registering job' );

	addAction( 'npm_install_finished', 'runGruntWatch', runGruntWatch );
	addAction( 'preference_saved', 'preferenceSaved', preferenceSaved, 9 );
	addAction( 'shutdown', 'shutdown', shutdown );

	cwd = preferences.value( 'basic', 'wordpress-folder' );

	if ( ! cwd ) {
		return;
	}

	const gruntfileJs = normalize( cwd + '/Gruntfile.js' );

	if ( existsSync( gruntfileJs ) ) {
		debug( 'Registering Gruntfile.js watcher' );
		watch( gruntfileJs ).on( 'change', () => {
			debug( 'Gruntfile.js change detected' );
			runGruntWatch();
		} );
github gambitph / Stackable / src / components / responsive-toggle / index.js View on Github external
componentDidMount() {
		const { instanceId } = this.props
		addAction( 'stackable.responsive-toggle.screen.change', `stackable/responsive-toggle-${ instanceId }`, this.onOtherScreenChange.bind( this ) )
		addAction( 'stackable.responsive-toggle.screen.open', `stackable/responsive-toggle-${ instanceId }`, this.onOtherScreenOpen.bind( this ) )
		addAction( 'stackable.responsive-toggle.screen.close', `stackable/responsive-toggle-${ instanceId }`, this.onOtherScreenClose.bind( this ) )
	}
github htmlburger / carbon-fields / packages / core / hocs / with-filters / index.js View on Github external
constructor( props ) {
				super( props );

				this.onHooksUpdated = this.onHooksUpdated.bind( this );
				this.Component = applyFilters( hookName, OriginalComponent );
				this.namespace = uniqueId( 'core/with-filters/component-' );
				this.throttledForceUpdate = debounce( () => {
					this.Component = applyFilters( hookName, OriginalComponent );
					this.forceUpdate();
				}, ANIMATION_FRAME_PERIOD );

				addAction( 'hookRemoved', this.namespace, this.onHooksUpdated );
				addAction( 'hookAdded', this.namespace, this.onHooksUpdated );
			}
github WordPress / gutenberg / packages / blocks / src / deprecated-hooks.js View on Github external
'blocks.Autocomplete.completers',
		'blocks.BlockEdit',
		'blocks.BlockListBlock',
		'blocks.MediaUpload',
	];
	if ( includes( deprecatedHooks, oldHookName ) ) {
		const newHookName = oldHookName.replace( 'blocks.', 'editor.' );
		deprecated( `${ oldHookName } filter`, {
			version: '3.3',
			alternative: newHookName,
		} );
		addFilter( newHookName, ...args );
	}
};

addAction( 'hookAdded', 'core/editor/deprecated', forwardDeprecatedHooks );
github htmlburger / carbon-fields / packages / metaboxes / index.js View on Github external
/**
 * Sets the locale data for the package type
 */
setLocaleData( window.cf.config.locale, 'carbon-fields-ui' );

/**
 * Determines the rendering context.
 *
 * @type {string}
 */
const context = isGutenberg() ? 'gutenberg' : 'classic';

/**
 * Abracadabra! Poof! Containers everywhere ...
 */
addAction( 'carbon-fields.init', 'carbon-fields/metaboxes', () => {
	initializeContainers( context );
	initializeMonitors( context );
} );