Skip to content

Commit 39f4a9f

Browse files
committed
Provide the default registry by using the default value of the createContext API
1 parent 27902d7 commit 39f4a9f

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/data/src/components/registry-provider/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
*/
44
import { createContext } from '@wordpress/element';
55

6-
const { Consumer, Provider } = createContext( null );
6+
/**
7+
* Internal dependencies
8+
*/
9+
import defaultRegistry from '../../default-registry';
10+
11+
const { Consumer, Provider } = createContext( defaultRegistry );
712

813
export const RegistryConsumer = Consumer;
914

packages/data/src/components/with-dispatch/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
/**
1818
* Internal dependencies
1919
*/
20-
import defaultRegistry from '../../default-registry';
2120
import { RegistryConsumer } from '../registry-provider';
2221

2322
/**
@@ -50,15 +49,13 @@ const withDispatch = ( mapDispatchToProps ) => createHigherOrderComponent(
5049

5150
proxyDispatch( propName, ...args ) {
5251
// Original dispatcher is a pre-bound (dispatching) action creator.
53-
const dispatch = this.props.registry ? this.props.registry.dispatch : defaultRegistry.dispatch;
54-
mapDispatchToProps( dispatch, this.props.ownProps )[ propName ]( ...args );
52+
mapDispatchToProps( this.props.registry.dispatch, this.props.ownProps )[ propName ]( ...args );
5553
}
5654

5755
setProxyProps( props ) {
5856
// Assign as instance property so that in reconciling subsequent
5957
// renders, the assigned prop values are referentially equal.
60-
const dispatch = props.registry ? props.registry.dispatch : defaultRegistry.dispatch;
61-
const propsToDispatchers = mapDispatchToProps( dispatch, props.ownProps );
58+
const propsToDispatchers = mapDispatchToProps( this.props.registry.dispatch, props.ownProps );
6259
this.proxyProps = mapValues( propsToDispatchers, ( dispatcher, propName ) => {
6360
// Prebind with prop name so we have reference to the original
6461
// dispatcher to invoke. Track between re-renders to avoid

packages/data/src/components/with-select/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import isShallowEqual from '@wordpress/is-shallow-equal';
1111
/**
1212
* Internal dependencies
1313
*/
14-
import defaultRegistry from '../../default-registry';
1514
import { RegistryConsumer } from '../registry-provider';
1615

1716
/**
@@ -40,9 +39,8 @@ const withSelect = ( mapStateToProps ) => createHigherOrderComponent( ( WrappedC
4039
// A constant value is used as the fallback since it can be more
4140
// efficiently shallow compared in case component is repeatedly
4241
// rendered without its own merge props.
43-
const select = props.registry ? props.registry.select : defaultRegistry.select;
4442
const mergeProps = (
45-
mapStateToProps( select, props.ownProps ) ||
43+
mapStateToProps( props.registry.select, props.ownProps ) ||
4644
DEFAULT_MERGE_PROPS
4745
);
4846

@@ -66,8 +64,7 @@ const withSelect = ( mapStateToProps ) => createHigherOrderComponent( ( WrappedC
6664
}
6765

6866
subscribe() {
69-
const subscribe = this.props.registry ? this.props.registry.subscribe : defaultRegistry.subscribe;
70-
this.unsubscribe = subscribe( () => {
67+
this.unsubscribe = this.props.registry.subscribe( () => {
7168
if ( ! this.canRunSelection ) {
7269
return;
7370
}

0 commit comments

Comments
 (0)