Skip to content

Commit

Permalink
Re-add & deprecate core/editor:getReferenceByDistinctEdits (#17458)
Browse files Browse the repository at this point in the history
Follow-up of #16490
  • Loading branch information
mcsf authored and youknowriad committed Sep 18, 2019
1 parent a0da94f commit 08819dc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ _Related_

- getPreviousBlockClientId in core/block-editor store.

<a name="getReferenceByDistinctEdits" href="#getReferenceByDistinctEdits">#</a> **getReferenceByDistinctEdits**

> **Deprecated** since Gutenberg 6.5.0.
Returns a new reference when edited values have changed. This is useful in
inferring where an edit has been made between states by comparison of the
return values using strict equality.

_Usage_

const hasEditOccurred = (
getReferenceByDistinctEdits( beforeState ) !==
getReferenceByDistinctEdits( afterState )
);

_Parameters_

- _state_ `Object`: Editor state.

_Returns_

- `*`: A value whose reference will change only when an edit occurs.

<a name="getSelectedBlock" href="#getSelectedBlock">#</a> **getSelectedBlock**

_Related_
Expand Down
30 changes: 30 additions & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,36 @@ export const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId ) || EMPTY_OBJECT;
} );

/**
* Returns a new reference when edited values have changed. This is useful in
* inferring where an edit has been made between states by comparison of the
* return values using strict equality.
*
* @deprecated since Gutenberg 6.5.0.
*
* @example
*
* ```
* const hasEditOccurred = (
* getReferenceByDistinctEdits( beforeState ) !==
* getReferenceByDistinctEdits( afterState )
* );
* ```
*
* @param {Object} state Editor state.
*
* @return {*} A value whose reference will change only when an edit occurs.
*/
export const getReferenceByDistinctEdits = createRegistrySelector(
( select ) => ( /* state */ ) => {
deprecated( '`wp.data.select( \'core/editor\' ).getReferenceByDistinctEdits`', {
alternative: '`wp.data.select( \'core\' ).getReferenceByDistinctEdits`',
} );

return select( 'core' ).getReferenceByDistinctEdits();
}
);

/**
* Returns an attribute value of the saved post.
*
Expand Down

0 comments on commit 08819dc

Please sign in to comment.