Skip to content

Commit

Permalink
USe more intuitive naming
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Nov 25, 2020
1 parent ececd96 commit 59e269c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
20 changes: 10 additions & 10 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { v4 as uuid } from 'uuid';
/**
* WordPress dependencies
*/
import { createAsyncRegistryAction } from '@wordpress/data';
import { createRegistryAction } from '@wordpress/data';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';

Expand Down Expand Up @@ -224,7 +224,7 @@ export function* deleteEntityRecord( kind, name, recordId, query ) {
*
* @return {Object} Action object.
*/
export const editEntityRecord = createAsyncRegistryAction(
export const editEntityRecord = createRegistryAction(
( { select } ) => async ( kind, name, recordId, edits, options = {} ) => {
const entity = select( 'core', 'getEntity', kind, name );
if ( ! entity ) {
Expand Down Expand Up @@ -282,36 +282,36 @@ export const editEntityRecord = createAsyncRegistryAction(
* Action triggered to undo the last edit to
* an entity record, if any.
*/
export const undo = createAsyncRegistryAction( ( { select } ) => () => {
export const undo = createRegistryAction( ( { select, yieldAction } ) => () => {
const undoEdit = select( 'core' ).getUndoEdit();
if ( ! undoEdit ) {
return;
}
return {
yieldAction( {
type: 'EDIT_ENTITY_RECORD',
...undoEdit,
meta: {
isUndo: true,
},
};
} );
} );

/**
* Action triggered to redo the last undoed
* edit to an entity record, if any.
*/
export const redo = createAsyncRegistryAction( ( { select } ) => () => {
export const redo = createRegistryAction( ( { select, yieldAction } ) => () => {
const redoEdit = select( 'core' ).getRedoEdit();
if ( ! redoEdit ) {
return;
}
return {
yieldAction( {
type: 'EDIT_ENTITY_RECORD',
...redoEdit,
meta: {
isRedo: true,
},
};
} );
} );

/**
Expand All @@ -332,7 +332,7 @@ export function __unstableCreateUndoLevel() {
* @param {Object} options Saving options.
* @param {boolean} [options.isAutosave=false] Whether this is an autosave.
*/
export const saveEntityRecord = createAsyncRegistryAction(
export const saveEntityRecord = createRegistryAction(
( { select, dispatch, yieldAction } ) => async (
kind,
name,
Expand Down Expand Up @@ -614,7 +614,7 @@ export const saveEntityRecord = createAsyncRegistryAction(
* @param {Object} recordId ID of the record.
* @param {Object} options Saving options.
*/
export const saveEditedEntityRecord = createAsyncRegistryAction(
export const saveEditedEntityRecord = createRegistryAction(
( { select, dispatch } ) => ( kind, name, recordId, options ) => {
if (
! select( 'core' ).hasEditsForEntityRecord( kind, name, recordId )
Expand Down
22 changes: 11 additions & 11 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { find, includes, get, hasIn, compact, uniq } from 'lodash';
*/
import { addQueryArgs } from '@wordpress/url';
import deprecated from '@wordpress/deprecated';
import { controls, createAsyncRegistryAction } from '@wordpress/data';
import { controls, createRegistryAction } from '@wordpress/data';
import { apiFetch } from '@wordpress/data-controls';
import triggerFetch from '@wordpress/api-fetch';

Expand All @@ -25,7 +25,7 @@ import { ifNotResolved, getNormalizedCommaSeparable } from './utils';
* @param {Object|undefined} query Optional object of query parameters to
* include with request.
*/
export const getAuthors = createAsyncRegistryAction(
export const getAuthors = createRegistryAction(
( { dispatch } ) => async ( query ) => {
const path = addQueryArgs(
'/wp/v2/users/?who=authors&per_page=100',
Expand All @@ -41,7 +41,7 @@ export const getAuthors = createAsyncRegistryAction(
*
* @param {number} id The author id.
*/
export const __unstableGetAuthor = createAsyncRegistryAction(
export const __unstableGetAuthor = createRegistryAction(
( { dispatch } ) => async ( id ) => {
const path = `/wp/v2/users?who=authors&include=${ id }`;
const users = await triggerFetch( { path } );
Expand All @@ -52,7 +52,7 @@ export const __unstableGetAuthor = createAsyncRegistryAction(
/**
* Requests the current user from the REST API.
*/
export const getCurrentUser = createAsyncRegistryAction(
export const getCurrentUser = createRegistryAction(
( { dispatch } ) => async () => {
const currentUser = await triggerFetch( { path: '/wp/v2/users/me' } );
return dispatch( 'core' ).receiveCurrentUser( currentUser );
Expand All @@ -68,7 +68,7 @@ export const getCurrentUser = createAsyncRegistryAction(
* @param {Object|undefined} query Optional object of query parameters to
* include with request.
*/
export const getEntityRecord = createAsyncRegistryAction(
export const getEntityRecord = createRegistryAction(
( { yieldAction, select, dispatch } ) => async (
kind,
name,
Expand Down Expand Up @@ -167,7 +167,7 @@ export const getEditedEntityRecord = ifNotResolved(
* @param {string} name Entity name.
* @param {Object?} query Query Object.
*/
export const getEntityRecords = createAsyncRegistryAction(
export const getEntityRecords = createRegistryAction(
( { yieldAction, dispatch } ) => async ( kind, name, query = {} ) => {
const entities = await yieldAction( getKindEntities( kind ) );
const entity = find( entities, { kind, name } );
Expand Down Expand Up @@ -262,7 +262,7 @@ getEntityRecords.shouldInvalidate = ( action, kind, name ) => {
/**
* Requests the current theme.
*/
export const getCurrentTheme = createAsyncRegistryAction(
export const getCurrentTheme = createRegistryAction(
( { dispatch } ) => async () => {
const activeThemes = await triggerFetch( {
path: '/wp/v2/themes?status=active',
Expand All @@ -274,7 +274,7 @@ export const getCurrentTheme = createAsyncRegistryAction(
/**
* Requests theme supports data from the index.
*/
export const getThemeSupports = createAsyncRegistryAction(
export const getThemeSupports = createRegistryAction(
( { dispatch } ) => async () => {
const activeThemes = await triggerFetch( {
path: '/wp/v2/themes?status=active',
Expand All @@ -290,7 +290,7 @@ export const getThemeSupports = createAsyncRegistryAction(
*
* @param {string} url URL to get the preview for.
*/
export const getEmbedPreview = createAsyncRegistryAction(
export const getEmbedPreview = createRegistryAction(
( { dispatch } ) => async ( url ) => {
try {
const embedProxyResponse = await triggerFetch( {
Expand All @@ -313,7 +313,7 @@ export const getEmbedPreview = createAsyncRegistryAction(
* @deprecated since 5.0. Callers should use the more generic `canUser()` selector instead of
* `hasUploadPermissions()`, e.g. `canUser( 'create', 'media' )`.
*/
export const hasUploadPermissions = createAsyncRegistryAction(
export const hasUploadPermissions = createRegistryAction(
( { dispatch } ) => async () => {
deprecated( "select( 'core' ).hasUploadPermissions()", {
alternative: "select( 'core' ).canUser( 'create', 'media' )",
Expand All @@ -331,7 +331,7 @@ export const hasUploadPermissions = createAsyncRegistryAction(
* @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
* @param {?string} id ID of the rest resource to check.
*/
export const canUser = createAsyncRegistryAction(
export const canUser = createRegistryAction(
( { dispatch } ) => async ( action, resource, id ) => {
const methods = {
create: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions packages/data/src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export function createRegistryControl( registryControl ) {
/**
* @TODO Documentation
*/
export function createAsyncRegistryAction( callback ) {
export function createRegistryAction( callback ) {
const wrapper = ( ...args ) => callback( wrapper.registryArgs )( ...args );
wrapper.isAsyncRegistryAction = true;
wrapper.isRegistryAction = true;
return wrapper;
}
2 changes: 1 addition & 1 deletion packages/data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { createRegistry } from './registry';
export {
createRegistrySelector,
createRegistryControl,
createAsyncRegistryAction,
createRegistryAction,
} from './factory';
export { controls } from './controls';
export { default as createReduxStore } from './redux-store';
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/promise-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isPromise from 'is-promise';
const promiseMiddleware = () => ( next ) => ( action ) => {
if ( isPromise( action ) ) {
return action.then( ( resolvedAction ) => {
if ( action.isAsyncAction ) {
if ( action.isRegistryAction ) {
return resolvedAction;
} else if ( resolvedAction ) {
return next( resolvedAction );
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/redux-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function mapResolvers( resolvers, selectors, store, resolversCache ) {
}

function mapRegistryAsyncAction( action, store ) {
if ( action.isAsyncRegistryAction && ! action.registryArgs ) {
if ( action.isRegistryAction && ! action.registryArgs ) {
action.registryArgs = {
dispatch: dataDispatch,
select: dataSelect,
Expand Down

0 comments on commit 59e269c

Please sign in to comment.