diff --git a/docs/data/data-core.md b/docs/data/data-core.md index 7dd17fa91a664f..44430e8261fa70 100644 --- a/docs/data/data-core.md +++ b/docs/data/data-core.md @@ -2,54 +2,6 @@ ## Selectors -### getTerms - -Returns all the available terms for the given taxonomy. - -*Parameters* - - * state: Data state. - * taxonomy: Taxonomy name. - -### getCategories - -Returns all the available categories. - -*Parameters* - - * state: Data state. - -*Returns* - -Categories list. - -### isRequestingTerms - -Returns true if a request is in progress for terms data of a given taxonomy, -or false otherwise. - -*Parameters* - - * state: Data state. - * taxonomy: Taxonomy name. - -*Returns* - -Whether a request is in progress for taxonomy's terms. - -### isRequestingCategories - -Returns true if a request is in progress for categories data, or false -otherwise. - -*Parameters* - - * state: Data state. - -*Returns* - -Whether a request is in progress for categories. - ### getAuthors Returns all available authors. @@ -118,16 +70,6 @@ Index data. ## Actions -### receiveTerms - -Returns an action object used in signalling that terms have been received -for a given taxonomy. - -*Parameters* - - * taxonomy: Taxonomy name. - * terms: Terms received. - ### receiveUserQuery Returns an action object used in signalling that authors have been received. diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 49c8775c12de46..ec98ffb883b292 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -3,6 +3,11 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo ## 3.7.0 - `wp.components.withAPIData` has been removed. Please use the Core Data module or `wp.apiFetch` directly instead. + - `wp.data.dispatch("core").receiveTerms` has been deprecated. Please use `wp.data.dispatch("core").receiveEntityRecords` instead. + - `getCategories` resolvers has been deprecated. Please use `getEntityRecords` resolver instead. + - `wp.data.select("core").getTerms` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead. + - `wp.data.select("core").getCategories` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead. + - `wp.data.select("core").isRequestingTerms` has been deprecated. Please use `wp.data.select("core").getEntitiesByKind` instead. ## 3.6.0 diff --git a/packages/core-data/README.md b/packages/core-data/README.md index ae7e4395882c1b..0afd5d02beb9ea 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -14,33 +14,24 @@ npm install @wordpress/core-data --save ## Example -Below is an example of a component which simply renders a list of categories: +Below is an example of a component which simply renders a list of authors: ```jsx const { withSelect } = wp.data; -function MyCategoriesList( { categories, isRequesting } ) { - if ( isRequesting ) { - return 'Loading…'; - } - +function MyAuthorsList( { authors } ) { return ( ); } -MyCategoriesList = withSelect( ( select ) => { - const { getCategories, isRequestingCategories } = select( 'core' ); - - return { - categories: getCategories(), - isRequesting: isRequestingCategories(), - }; -} ); +MyAuthorsList = withSelect( ( select ) => ( { + authors: select( 'core' ).getAuthors(), +} ) ); ``` ## Actions diff --git a/packages/core-data/src/actions.js b/packages/core-data/src/actions.js index 06afd03354f971..8ce1befbb86ba9 100644 --- a/packages/core-data/src/actions.js +++ b/packages/core-data/src/actions.js @@ -2,6 +2,7 @@ * External dependencies */ import { castArray } from 'lodash'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -21,6 +22,11 @@ import { * @return {Object} Action object. */ export function receiveTerms( taxonomy, terms ) { + deprecated( 'wp.data.dispatch("core").receiveTerms', { + version: '3.7.0', + alternative: 'wp.data.dispatch("core").receiveEntityRecords', + plugin: 'Gutenberg', + } ); return { type: 'RECEIVE_TERMS', taxonomy, diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index 7d939de0fac4a6..e9ec41f577650f 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -8,6 +8,7 @@ import { find } from 'lodash'; */ import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -26,6 +27,11 @@ import { getKindEntities } from './entities'; * progress. */ export async function* getCategories() { + deprecated( 'getCategories resolver', { + version: '3.7.0', + alternative: 'getEntityRecords resolver', + plugin: 'Gutenberg', + } ); const categories = await apiFetch( { path: '/wp/v2/categories?per_page=-1' } ); yield receiveTerms( 'categories', categories ); } diff --git a/packages/core-data/src/selectors.js b/packages/core-data/src/selectors.js index 1e0fd66f63f11a..00af63aa6e147d 100644 --- a/packages/core-data/src/selectors.js +++ b/packages/core-data/src/selectors.js @@ -8,6 +8,7 @@ import { map, find, get, filter } from 'lodash'; * WordPress dependencies */ import { select } from '@wordpress/data'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -37,6 +38,11 @@ function isResolving( selectorName, ...args ) { * @return {Array} Categories list. */ export function getTerms( state, taxonomy ) { + deprecated( 'wp.data.select("core").getTerms', { + version: '3.7.0', + alternative: 'wp.data.select("core").getEntityRecords', + plugin: 'Gutenberg', + } ); return state.terms[ taxonomy ]; } @@ -48,6 +54,11 @@ export function getTerms( state, taxonomy ) { * @return {Array} Categories list. */ export function getCategories( state ) { + deprecated( 'wp.data.select("core").getCategories', { + version: '3.7.0', + alternative: 'wp.data.select("core").getEntityRecords', + plugin: 'Gutenberg', + } ); return getTerms( state, 'categories' ); } @@ -61,6 +72,11 @@ export function getCategories( state ) { * @return {boolean} Whether a request is in progress for taxonomy's terms. */ export function isRequestingTerms( state, taxonomy ) { + deprecated( 'wp.data.select("core").isRequestingTerms', { + version: '3.7.0', + alternative: 'wp.data.select("core").getEntitiesByKind', + plugin: 'Gutenberg', + } ); return isResolving( 'getTerms', taxonomy ); } @@ -73,6 +89,11 @@ export function isRequestingTerms( state, taxonomy ) { * @return {boolean} Whether a request is in progress for categories. */ export function isRequestingCategories() { + deprecated( 'wp.data.select("core").isRequestingCategories', { + version: '3.7.0', + alternative: 'wp.data.select("core").getEntitiesByKind', + plugin: 'Gutenberg', + } ); return isResolving( 'getCategories' ); } diff --git a/packages/core-data/src/test/resolvers.js b/packages/core-data/src/test/resolvers.js index 581830a04f3f29..55eef7026b4bbc 100644 --- a/packages/core-data/src/test/resolvers.js +++ b/packages/core-data/src/test/resolvers.js @@ -31,6 +31,7 @@ describe( 'getCategories', () => { const fulfillment = getCategories(); const received = ( await fulfillment.next() ).value; expect( received ).toEqual( receiveTerms( 'categories', CATEGORIES ) ); + expect( console ).toHaveWarnedWith( 'getCategories resolver is deprecated and will be removed from Gutenberg in 3.7.0. Please use getEntityRecords resolver instead.' ); } ); } ); diff --git a/packages/core-data/src/test/selectors.js b/packages/core-data/src/test/selectors.js index d06fdc1fc9c3a2..35bd9f7bdee31e 100644 --- a/packages/core-data/src/test/selectors.js +++ b/packages/core-data/src/test/selectors.js @@ -37,6 +37,7 @@ describe( 'getTerms()', () => { }, } ); expect( getTerms( state, 'categories' ) ).toEqual( [ { id: 1 } ] ); + expect( console ).toHaveWarnedWith( 'wp.data.select("core").getTerms is deprecated and will be removed from Gutenberg in 3.7.0. Please use wp.data.select("core").getEntityRecords instead.' ); } ); } ); @@ -58,6 +59,7 @@ describe( 'isRequestingCategories()', () => { it( 'returns false if never requested', () => { const result = isRequestingCategories(); expect( result ).toBe( false ); + expect( console ).toHaveWarnedWith( 'wp.data.select("core").isRequestingCategories is deprecated and will be removed from Gutenberg in 3.7.0. Please use wp.data.select("core").getEntitiesByKind instead.' ); } ); it( 'returns false if categories resolution finished', () => {