2018-11-29 15:57:49 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { registerGenericStore } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import createApiClient from './create-api-client';
|
|
|
|
import wcApiSpec from '../wc-api-spec';
|
|
|
|
|
|
|
|
function createWcApiStore() {
|
|
|
|
const apiClient = createApiClient( 'wc-api', wcApiSpec );
|
|
|
|
|
|
|
|
function getComponentSelectors( component ) {
|
|
|
|
const componentRequirements = [];
|
|
|
|
|
2018-12-07 23:04:52 +00:00
|
|
|
return {
|
|
|
|
selectors: apiClient.getSelectors( componentRequirements ),
|
|
|
|
onComplete: () => {
|
|
|
|
if ( 0 === componentRequirements.length ) {
|
|
|
|
apiClient.clearComponentRequirements( component );
|
|
|
|
} else {
|
|
|
|
apiClient.setComponentRequirements( component, componentRequirements );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2018-11-29 15:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
// The wrapped function for getSelectors is temporary code.
|
|
|
|
//
|
|
|
|
// TODO: Remove the `() =>` after the `@wordpress/data` PR is merged:
|
|
|
|
// https://github.com/WordPress/gutenberg/pull/11460
|
|
|
|
//
|
|
|
|
getSelectors: () => context => {
|
|
|
|
const component = context && context.component ? context.component : context;
|
|
|
|
return getComponentSelectors( component );
|
|
|
|
},
|
|
|
|
getActions() {
|
|
|
|
// TODO: Add mutations here.
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
subscribe: apiClient.subscribe,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
registerGenericStore( 'wc-api', createWcApiStore() );
|