Skip to content

Commit

Permalink
Provide the default registry by using the default value of the create…
Browse files Browse the repository at this point in the history
…Context API
  • Loading branch information
youknowriad committed Jun 27, 2018
1 parent bdc7ffe commit 0e46b9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 6 additions & 1 deletion packages/data/src/components/registry-provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
*/
import { createContext } from '@wordpress/element';

const { Consumer, Provider } = createContext( null );
/**
* Internal dependencies
*/
import defaultRegistry from '../../default-registry';

const { Consumer, Provider } = createContext( defaultRegistry );

export const RegistryConsumer = Consumer;

Expand Down
7 changes: 2 additions & 5 deletions packages/data/src/components/with-dispatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
/**
* Internal dependencies
*/
import defaultRegistry from '../../default-registry';
import { RegistryConsumer } from '../registry-provider';

/**
Expand Down Expand Up @@ -50,15 +49,13 @@ const withDispatch = ( mapDispatchToProps ) => createHigherOrderComponent(

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

setProxyProps( props ) {
// Assign as instance property so that in reconciling subsequent
// renders, the assigned prop values are referentially equal.
const dispatch = props.registry ? props.registry.dispatch : defaultRegistry.dispatch;
const propsToDispatchers = mapDispatchToProps( dispatch, props.ownProps );
const propsToDispatchers = mapDispatchToProps( this.props.registry.dispatch, props.ownProps );
this.proxyProps = mapValues( propsToDispatchers, ( dispatcher, propName ) => {
// Prebind with prop name so we have reference to the original
// dispatcher to invoke. Track between re-renders to avoid
Expand Down
7 changes: 2 additions & 5 deletions packages/data/src/components/with-select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import isShallowEqual from '@wordpress/is-shallow-equal';
/**
* Internal dependencies
*/
import defaultRegistry from '../../default-registry';
import { RegistryConsumer } from '../registry-provider';

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

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

subscribe() {
const subscribe = this.props.registry ? this.props.registry.subscribe : defaultRegistry.subscribe;
this.unsubscribe = subscribe( () => {
this.unsubscribe = this.props.registry.subscribe( () => {
if ( ! this.canRunSelection ) {
return;
}
Expand Down

0 comments on commit 0e46b9a

Please sign in to comment.