How to use the @wordpress/hooks.createHooks 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 / packages / blocks / src / api / factory.js View on Github external
export function findTransform( transforms, predicate ) {
	// The hooks library already has built-in mechanisms for managing priority
	// queue, so leverage via locally-defined instance.
	const hooks = createHooks();

	for ( let i = 0; i < transforms.length; i++ ) {
		const candidate = transforms[ i ];
		if ( predicate( candidate ) ) {
			hooks.addFilter(
				'transform',
				'transform/' + i.toString(),
				( result ) => result ? result : candidate,
				candidate.priority
			);
		}
	}

	// Filter name is arbitrarily chosen but consistent with above aggregation.
	return hooks.applyFilters( 'transform', null );
}
github WordPress / gutenberg / blocks / api / factory.js View on Github external
export function findTransform( transforms, predicate ) {
	// The hooks library already has built-in mechanisms for managing priority
	// queue, so leverage via locally-defined instance.
	const hooks = createHooks();

	for ( let i = 0; i < transforms.length; i++ ) {
		const candidate = transforms[ i ];
		if ( predicate( candidate ) ) {
			hooks.addFilter(
				'transform',
				'transform/' + i.toString(),
				( result ) => result ? result : candidate,
				candidate.priority
			);
		}
	}

	// Filter name is arbitrarily chosen but consistent with above aggregation.
	return hooks.applyFilters( 'transform', null );
}
github wp-erp / wp-erp / modules / accounting / assets / src / admin / bootstrap.js View on Github external
window.acct.libs['TimePicker']       = TimePicker;
window.acct.libs['SelectPeople']     = SelectPeople;
window.acct.libs['DynamicTrnLoader'] = DynamicTrnLoader;
window.acct.libs['Vuelidate']        = Vuelidate;
window.acct.libs['PieChart']         = PieChart;
window.acct.libs['VueClipboards']    = VueClipboards;
window.acct.libs['clickOutside']     = clickOutside;

// get lib reference from window
window.acct_get_lib = function(lib) {
    return window.acct.libs[lib];
};

// hook manipulation
/* global acct */
acct.hooks = createHooks();

acct.addFilter = (hookName, namespace, component, priority = 10) => {
    acct.hooks.addFilter(hookName, namespace, (components) => {
        components.push(component);
        return components;
    }, priority);
};
github wponion / wponion / src / js / wponion-core.js View on Github external
$.fn = $.extend( $.fn, jquery_functions );

		window.tippy               = tippy;
		window.tippy_plugins       = {
			'followCursor': followCursor,
			'animateFill': animateFill,
			'inlinePositioning': inlinePositioning,
			'sticky': sticky
		};
		window.wpo_core            = WPOnion_Core;
		window.wponion             = {};
		window.wponion.instances   = {};
		window.wponion.plugins     = {};
		window.wponion.class       = {};
		window.wponion._           = window.lodash.noConflict();
		window.wponion.hooks       = createHooks();
		window.wponion.helper      = vsp_js_helper;
		window.wponion.object_path = WPOnion_Object_Path;
		/*window.wponion.instances.module  = new instance_handler();
		window.wponion.instances.fields  = new instance_handler();
		window.wponion.instances.global  = new instance_handler();*/
		window.wponion.plugins.bs_button = wpo_button;
		window.wponion.plugins.ajaxer    = WPOnion_Ajaxer;
		window.wponion.plugins.validator = WPOnion_Validator;
		window.wponion.class.base        = WPOnion_Base;
		window.wponion.class.theme_base  = WPOnion_Theme_Base;
		window.wponion.class.module_base = WPOnion_Module_Base;
		window.wponion.class.field_debug = new WPOnion_Debug();
		window.wponion.class.field_base  = WPOnion_Field_Base;
		window.wponion.class.field       = WPOnion_Field;
		window.wponion.class.dependency  = WPOnion_Dependency;
	}