Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type: 'RESOLVE_SELECT',
selectorName,
args,
};
}
const controls = {
API_FETCH( { request } ) {
return triggerApiFetch( request );
},
SELECT: createRegistryControl( ( registry ) => ( { selectorName, args } ) => {
return registry.select( 'core' )[ selectorName ]( ...args );
} ),
RESOLVE_SELECT: createRegistryControl(
( registry ) => ( { selectorName, args } ) => {
return new Promise( ( resolve ) => {
const hasFinished = () => registry.select( 'core/data' )
.hasFinishedResolution( 'core', selectorName, args );
const getResult = () => registry.select( 'core' )[ selectorName ]
.apply( null, args );
// trigger the selector (to trigger the resolver)
const result = getResult();
if ( hasFinished() ) {
return resolve( result );
}
const unsubscribe = registry.subscribe( () => {
if ( hasFinished() ) {
unsubscribe();
* @return {Object} control descriptor.
*/
export function resolveSelect( selectorName, ...args ) {
return {
type: 'RESOLVE_SELECT',
selectorName,
args,
};
}
const controls = {
API_FETCH( { request } ) {
return triggerApiFetch( request );
},
SELECT: createRegistryControl( ( registry ) => ( { selectorName, args } ) => {
return registry.select( 'core' )[ selectorName ]( ...args );
} ),
RESOLVE_SELECT: createRegistryControl(
( registry ) => ( { selectorName, args } ) => {
return new Promise( ( resolve ) => {
const hasFinished = () => registry.select( 'core/data' )
.hasFinishedResolution( 'core', selectorName, args );
const getResult = () => registry.select( 'core' )[ selectorName ]
.apply( null, args );
// trigger the selector (to trigger the resolver)
const result = getResult();
if ( hasFinished() ) {
return resolve( result );
}
* reducer,
* controls,
* actions,
* selectors,
* resolvers,
* } );
* ```
*
* @return {Object} An object for registering the default controls with the
* store.
*/
export const controls = {
API_FETCH( { request } ) {
return triggerFetch( request );
},
SELECT: createRegistryControl(
( registry ) => ( { storeKey, selectorName, args } ) => {
return registry.select( storeKey )[ selectorName ].hasResolver ?
resolveSelect( registry, { storeKey, selectorName, args } ) :
registry.select( storeKey )[ selectorName ]( ...args );
}
),
DISPATCH: createRegistryControl(
( registry ) => ( { storeKey, actionName, args } ) => {
return registry.dispatch( storeKey )[ actionName ]( ...args );
}
),
};
* @param {string} selectorName Selector name.
* @param {Array} args Selector arguments.
*
* @return {Object} control descriptor.
*/
export function select( storeName, selectorName, ...args ) {
return {
type: 'SELECT',
storeName,
selectorName,
args,
};
}
const controls = {
SELECT: createRegistryControl(
( registry ) => ( { storeName, selectorName, args } ) => {
return registry.select( storeName )[ selectorName ]( ...args );
}
),
};
export default controls;
*
* @return {Object} An object for registering the default controls with the
* store.
*/
export const controls = {
API_FETCH( { request } ) {
return triggerFetch( request );
},
SELECT: createRegistryControl(
( registry ) => ( { storeKey, selectorName, args } ) => {
return registry.select( storeKey )[ selectorName ].hasResolver ?
resolveSelect( registry, { storeKey, selectorName, args } ) :
registry.select( storeKey )[ selectorName ]( ...args );
}
),
DISPATCH: createRegistryControl(
( registry ) => ( { storeKey, actionName, args } ) => {
return registry.dispatch( storeKey )[ actionName ]( ...args );
}
),
};
* @param {Array} assets A collection of URL for the assets.
*
* @return {Object} Control descriptor.
*/
export function* loadAssets( assets ) {
return {
type: 'LOAD_ASSETS',
assets,
};
}
const controls = {
SELECT: createRegistryControl( ( registry ) => ( { storeName, selectorName, args } ) => {
return registry.select( storeName )[ selectorName ]( ...args );
} ),
DISPATCH: createRegistryControl( ( registry ) => ( { storeName, dispatcherName, args } ) => {
return registry.dispatch( storeName )[ dispatcherName ]( ...args );
} ),
API_FETCH( { request } ) {
return wpApiFetch( { ... request } );
},
LOAD_ASSETS( { assets } ) {
return new Promise( ( resolve, reject ) => {
if ( Array.isArray( assets ) ) {
let scriptsCount = 0;
forEach( assets, ( asset ) => {
if ( asset.match( /\.js$/ ) !== null ) {
scriptsCount++;
loadScript( asset, () => {
scriptsCount--;
if ( scriptsCount === 0 ) {
/**
* Load the asset files for a block
*
* @param {Array} assets A collection of URL for the assets.
*
* @return {Object} Control descriptor.
*/
export function* loadAssets( assets ) {
return {
type: 'LOAD_ASSETS',
assets,
};
}
const controls = {
SELECT: createRegistryControl( ( registry ) => ( { storeName, selectorName, args } ) => {
return registry.select( storeName )[ selectorName ]( ...args );
} ),
DISPATCH: createRegistryControl( ( registry ) => ( { storeName, dispatcherName, args } ) => {
return registry.dispatch( storeName )[ dispatcherName ]( ...args );
} ),
API_FETCH( { request } ) {
return wpApiFetch( { ... request } );
},
LOAD_ASSETS( { assets } ) {
return new Promise( ( resolve, reject ) => {
if ( Array.isArray( assets ) ) {
let scriptsCount = 0;
forEach( assets, ( asset ) => {
if ( asset.match( /\.js$/ ) !== null ) {
scriptsCount++;