Fix withSelect to release resources on unmount (https://github.com/woocommerce/woocommerce-admin/pull/1999)

* Add fresh-data dev info support for dev builds.

This adds support for dev info to be accessed from the JavaScript
console for more information about resources handled by fresh-data.

* Update fresh-data to 0.6.0

* Fix withSelect to release resources on unmount

Previously, withSelect wasn't releasing resources from fresh-data when
it was unmounting. This fixes that behavior and now clears a component's
requirements correctly when unmounting.
This commit is contained in:
Kevin Killingsworth 2019-04-09 09:56:25 -05:00 committed by GitHub
parent 85fda4d61f
commit 007ff933ce
2 changed files with 4 additions and 2 deletions

View File

@ -59,7 +59,6 @@ const withSelect = mapSelectToProps =>
getNextMergeProps( props ) { getNextMergeProps( props ) {
const storeSelectors = {}; const storeSelectors = {};
const onCompletes = []; const onCompletes = [];
const onUnmounts = {};
const componentContext = { component: this }; const componentContext = { component: this };
const getStoreFromRegistry = ( key, registry, context ) => { const getStoreFromRegistry = ( key, registry, context ) => {
@ -72,7 +71,7 @@ const withSelect = mapSelectToProps =>
// We give it a context, and we check for a "resolve" // We give it a context, and we check for a "resolve"
const { selectors, onComplete, onUnmount } = selectorsForKey( context ); const { selectors, onComplete, onUnmount } = selectorsForKey( context );
onComplete && onCompletes.push( onComplete ); onComplete && onCompletes.push( onComplete );
onUnmount && ( onUnmounts[ key ] = onUnmount ); onUnmount && ( this.onUnmounts[ key ] = onUnmount );
storeSelectors[ key ] = selectors; storeSelectors[ key ] = selectors;
} else { } else {
storeSelectors[ key ] = selectorsForKey; storeSelectors[ key ] = selectorsForKey;

View File

@ -29,6 +29,9 @@ function createWcApiStore() {
apiClient.setComponentRequirements( component, componentRequirements ); apiClient.setComponentRequirements( component, componentRequirements );
} }
}, },
onUnmount: () => {
apiClient.clearComponentRequirements( component );
},
}; };
} }