Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat(connectStateResults): add component props (#434)
Browse files Browse the repository at this point in the history
deprecation warning about createConnector in favor of connectStateResults is fired only when mounting a component.
  • Loading branch information
mthuret authored Oct 9, 2017
1 parent 81d1af8 commit c629b97
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getResults } from '../core/indexUtils';
* @providedPropType {string} error - If the search failed, the error will be logged here.
* @providedPropType {boolean} searching - If there is a search in progress.
* @providedPropType {boolean} searchingForFacetValues - If there is a search in a list in progress.
* @providedPropType {boolean} props - component props.
* @example
* import React from 'react';
*
Expand Down Expand Up @@ -57,6 +58,7 @@ export default createConnector({
searching: searchResults.searching,
error: searchResults.error,
searchingForFacetValues: searchResults.searchingForFacetValues,
props,
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ describe('connectStateResults', () => {
searchingForFacetValues,
};

props = getProvidedProps({}, searchState, searchResults);
props = getProvidedProps({ props: 'props' }, searchState, searchResults);
expect(props).toEqual({
searchState,
searchResults: searchResults.results,
allSearchResults: searchResults.results,
error,
searching,
searchingForFacetValues,
props: { props: 'props' },
});
});
});
Expand All @@ -55,14 +56,15 @@ describe('connectStateResults', () => {
searchingForFacetValues,
};

props = getProvidedProps({}, searchState, searchResults);
props = getProvidedProps({ props: 'props' }, searchState, searchResults);
expect(props).toEqual({
searchState,
searchResults: searchResults.results.first,
allSearchResults: searchResults.results,
error,
searching,
searchingForFacetValues,
props: { props: 'props' },
});
});
});
Expand Down
59 changes: 29 additions & 30 deletions packages/react-instantsearch/src/core/createConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ export default function createConnector(connectorDesc) {
if (isWidget) {
this.unregisterWidget = widgetsManager.registerWidget(this);
}
if (process.env.NODE_ENV === 'development') {
const onlyGetProvidedPropsUsage = !Object.keys(connectorDesc).find(
key =>
[
'getMetadata',
'getSearchParameters',
'refine',
'cleanUp',
].indexOf(key) > -1
);

if (
onlyGetProvidedPropsUsage &&
!connectorDesc.displayName.startsWith('Algolia')
) {
// eslint-disable-next-line no-console
console.warn(
'react-instantsearch: it seems that you are using the `createConnector` api ' +
'only to access the `searchState` and the `searchResults` through `getProvidedProps`.' +
'We are now provided a dedicated API' +
' the `connectStateResults` connector that you should use instead. The `createConnector` API will be ' +
'soon deprecated and will break in future next major versions.' +
'\n\n' +
'See more at https://community.algolia.com/react-instantsearch/connectors/connectStateResults.html' +
'\n' +
'and https://community.algolia.com/react-instantsearch/guide/Conditional_display.html'
);
}
}
}

getMetadata(nextWidgetsState) {
Expand Down Expand Up @@ -272,36 +301,6 @@ export default function createConnector(connectorDesc) {
}
: {};

if (process.env.NODE_ENV === 'development') {
const onlyGetProvidedPropsUsage = !Object.keys(connectorDesc).find(
key =>
[
'getMetadata',
'getSearchParameters',
'refine',
'cleanUp',
].indexOf(key) > -1
);

if (
onlyGetProvidedPropsUsage &&
!connectorDesc.displayName.startsWith('Algolia')
) {
// eslint-disable-next-line no-console
console.warn(
'react-instantsearch: it seems that you are using the `createConnector` api ' +
'only to access the `searchState` and the `searchResults` through `getProvidedProps`.' +
'We are now provided a dedicated API' +
' the `connectStateResults` connector that you should use instead. The `createConnector` API will be ' +
'soon deprecated and will break in future next major versions.' +
'\n\n' +
'See more at https://community.algolia.com/react-instantsearch/connectors/connectStateResults.html' +
'\n' +
'and https://community.algolia.com/react-instantsearch/guide/Conditional_display.html'
);
}
}

return (
<Composed
{...this.props}
Expand Down

0 comments on commit c629b97

Please sign in to comment.