react-instantsearch-core
Advanced tools
Comparing version 6.0.0-beta.0 to 6.0.0-beta.1
@@ -80,13 +80,15 @@ "use strict"; | ||
var defaultProps = { | ||
transformItems: function transformItems(items) { | ||
return items; | ||
}, | ||
transformRuleContexts: function transformRuleContexts(ruleContexts) { | ||
return ruleContexts; | ||
}, | ||
trackedFilters: {} | ||
}; | ||
var _default = (0, _createConnector.default)({ | ||
displayName: 'AlgoliaQueryRules', | ||
defaultProps: { | ||
transformItems: function transformItems(items) { | ||
return items; | ||
}, | ||
transformRuleContexts: function transformRuleContexts(ruleContexts) { | ||
return ruleContexts; | ||
}, | ||
trackedFilters: {} | ||
}, | ||
defaultProps: defaultProps, | ||
getProvidedProps: function getProvidedProps(props, _1, searchResults) { | ||
@@ -93,0 +95,0 @@ var results = (0, _indexUtils.getResults)(searchResults, { |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _default = '6.0.0-beta.0'; | ||
var _default = '6.0.0-beta.1'; | ||
exports.default = _default; |
@@ -160,3 +160,3 @@ "use strict"; | ||
indexName: _propTypes.default.string.isRequired, | ||
indexId: _propTypes.default.string.isRequired | ||
indexId: _propTypes.default.string | ||
}; | ||
@@ -163,0 +163,0 @@ var IndexComponentWithoutContext = Index; |
@@ -16,10 +16,10 @@ "use strict"; | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); | ||
var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); | ||
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); | ||
@@ -31,2 +31,4 @@ | ||
var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
@@ -85,17 +87,29 @@ | ||
(0, _inherits2.default)(InstantSearch, _Component); | ||
(0, _createClass2.default)(InstantSearch, null, [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
var nextIsControlled = isControlled(nextProps); | ||
var previousSearchState = prevState.instantSearchManager.store.getState().widgets; | ||
var nextSearchState = nextProps.searchState; | ||
function InstantSearch() { | ||
var _getPrototypeOf2; | ||
if (nextIsControlled && !(0, _fastDeepEqual.default)(previousSearchState, nextSearchState)) { | ||
prevState.instantSearchManager.onExternalStateUpdate(nextProps.searchState); | ||
} | ||
return { | ||
isControlled: nextIsControlled, | ||
contextValue: (0, _objectSpread2.default)({}, prevState.contextValue, { | ||
mainTargetedIndex: nextProps.indexName | ||
}) | ||
}; | ||
} | ||
}]); | ||
function InstantSearch(props) { | ||
var _this; | ||
(0, _classCallCheck2.default)(this, InstantSearch); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(InstantSearch)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(InstantSearch).call(this, props)); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isUnmounting", false); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "aisManager", (0, _createInstantSearchManager.default)({ | ||
var instantSearchManager = (0, _createInstantSearchManager.default)({ | ||
indexName: _this.props.indexName, | ||
@@ -106,16 +120,18 @@ searchClient: _this.props.searchClient, | ||
stalledSearchDelay: _this.props.stalledSearchDelay | ||
})); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isControlled", isControlled(_this.props)); | ||
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", { | ||
contextValue: { | ||
onInternalStateUpdate: _this.onWidgetsInternalStateUpdate.bind((0, _assertThisInitialized2.default)(_this)), | ||
createHrefForState: _this.createHrefForState.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchForFacetValues: _this.onSearchForFacetValues.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchStateChange: _this.onSearchStateChange.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchParameters: _this.onSearchParameters.bind((0, _assertThisInitialized2.default)(_this)), | ||
store: _this.aisManager.store, | ||
widgetsManager: _this.aisManager.widgetsManager, | ||
mainTargetedIndex: _this.props.indexName | ||
} | ||
}); | ||
var contextValue = { | ||
store: instantSearchManager.store, | ||
widgetsManager: instantSearchManager.widgetsManager, | ||
mainTargetedIndex: _this.props.indexName, | ||
onInternalStateUpdate: _this.onWidgetsInternalStateUpdate.bind((0, _assertThisInitialized2.default)(_this)), | ||
createHrefForState: _this.createHrefForState.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchForFacetValues: _this.onSearchForFacetValues.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchStateChange: _this.onSearchStateChange.bind((0, _assertThisInitialized2.default)(_this)), | ||
onSearchParameters: _this.onSearchParameters.bind((0, _assertThisInitialized2.default)(_this)) | ||
}; | ||
_this.state = { | ||
isControlled: isControlled(_this.props), | ||
instantSearchManager: instantSearchManager, | ||
contextValue: contextValue | ||
}; | ||
return _this; | ||
@@ -127,31 +143,22 @@ } | ||
value: function componentDidUpdate(prevProps) { | ||
var nextIsControlled = isControlled(this.props); | ||
var prevIsControlled = isControlled(prevProps); | ||
if (!this.isControlled && nextIsControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being uncontrolled to controlled"); | ||
if (prevIsControlled && !this.state.isControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being controlled to uncontrolled"); | ||
} | ||
if (this.isControlled && !nextIsControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being controlled to uncontrolled"); | ||
if (!prevIsControlled && this.state.isControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being uncontrolled to controlled"); | ||
} | ||
/* | ||
* Clear cache when `refresh` changes to `true`. | ||
* Prevents users to always clear the cache on render if they forget to revert it to `false`. | ||
*/ | ||
if (this.props.refresh !== prevProps.refresh && this.props.refresh) { | ||
this.aisManager.clearCache(); | ||
this.state.instantSearchManager.clearCache(); | ||
} | ||
if (this.isControlled) { | ||
this.aisManager.onExternalStateUpdate(this.props.searchState); | ||
} | ||
if (prevProps.indexName !== this.props.indexName) { | ||
this.aisManager.updateIndex(this.props.indexName); | ||
this.state.instantSearchManager.updateIndex(this.props.indexName); | ||
} | ||
if (prevProps.searchClient !== this.props.searchClient) { | ||
this.aisManager.updateClient(this.props.searchClient); | ||
this.state.instantSearchManager.updateClient(this.props.searchClient); | ||
} | ||
@@ -163,3 +170,3 @@ } | ||
this.isUnmounting = true; | ||
this.aisManager.skipSearch(); | ||
this.state.instantSearchManager.skipSearch(); | ||
} | ||
@@ -169,4 +176,4 @@ }, { | ||
value: function createHrefForState(searchState) { | ||
searchState = this.aisManager.transitionState(searchState); | ||
return this.isControlled && this.props.createURL ? this.props.createURL(searchState, this.getKnownKeys()) : '#'; | ||
searchState = this.state.instantSearchManager.transitionState(searchState); | ||
return this.state.isControlled && this.props.createURL ? this.props.createURL(searchState, this.getKnownKeys()) : '#'; | ||
} | ||
@@ -176,7 +183,7 @@ }, { | ||
value: function onWidgetsInternalStateUpdate(searchState) { | ||
searchState = this.aisManager.transitionState(searchState); | ||
searchState = this.state.instantSearchManager.transitionState(searchState); | ||
this.onSearchStateChange(searchState); | ||
if (!this.isControlled) { | ||
this.aisManager.onExternalStateUpdate(searchState); | ||
if (!this.state.isControlled) { | ||
this.state.instantSearchManager.onExternalStateUpdate(searchState); | ||
} | ||
@@ -203,3 +210,3 @@ } | ||
value: function onSearchForFacetValues(searchState) { | ||
this.aisManager.onSearchForFacetValues(searchState); | ||
this.state.instantSearchManager.onSearchForFacetValues(searchState); | ||
} | ||
@@ -209,3 +216,3 @@ }, { | ||
value: function getKnownKeys() { | ||
return this.aisManager.getWidgetsIds(); | ||
return this.state.instantSearchManager.getWidgetsIds(); | ||
} | ||
@@ -223,11 +230,2 @@ }, { | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
return { | ||
contextValue: (0, _objectSpread2.default)({}, prevState.contextValue, { | ||
mainTargetedIndex: nextProps.indexName | ||
}) | ||
}; | ||
} | ||
}]); | ||
@@ -234,0 +232,0 @@ return InstantSearch; |
@@ -69,13 +69,14 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
var defaultProps = { | ||
transformItems: function transformItems(items) { | ||
return items; | ||
}, | ||
transformRuleContexts: function transformRuleContexts(ruleContexts) { | ||
return ruleContexts; | ||
}, | ||
trackedFilters: {} | ||
}; | ||
export default createConnector({ | ||
displayName: 'AlgoliaQueryRules', | ||
defaultProps: { | ||
transformItems: function transformItems(items) { | ||
return items; | ||
}, | ||
transformRuleContexts: function transformRuleContexts(ruleContexts) { | ||
return ruleContexts; | ||
}, | ||
trackedFilters: {} | ||
}, | ||
defaultProps: defaultProps, | ||
getProvidedProps: function getProvidedProps(props, _1, searchResults) { | ||
@@ -82,0 +83,0 @@ var results = getResults(searchResults, { |
@@ -1,1 +0,1 @@ | ||
export default '6.0.0-beta.0'; | ||
export default '6.0.0-beta.1'; |
@@ -144,5 +144,5 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
indexName: PropTypes.string.isRequired, | ||
indexId: PropTypes.string.isRequired | ||
indexId: PropTypes.string | ||
}; | ||
export var IndexComponentWithoutContext = Index; | ||
export default IndexWrapper; |
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread"; | ||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; | ||
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; | ||
import _createClass from "@babel/runtime/helpers/esm/createClass"; | ||
import _inherits from "@babel/runtime/helpers/esm/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import React, { Component, Children } from 'react'; | ||
import isEqual from 'fast-deep-equal'; | ||
import PropTypes from 'prop-types'; | ||
@@ -62,5 +63,23 @@ import createInstantSearchManager from '../core/createInstantSearchManager'; | ||
function InstantSearch() { | ||
var _getPrototypeOf2; | ||
_createClass(InstantSearch, null, [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
var nextIsControlled = isControlled(nextProps); | ||
var previousSearchState = prevState.instantSearchManager.store.getState().widgets; | ||
var nextSearchState = nextProps.searchState; | ||
if (nextIsControlled && !isEqual(previousSearchState, nextSearchState)) { | ||
prevState.instantSearchManager.onExternalStateUpdate(nextProps.searchState); | ||
} | ||
return { | ||
isControlled: nextIsControlled, | ||
contextValue: _objectSpread({}, prevState.contextValue, { | ||
mainTargetedIndex: nextProps.indexName | ||
}) | ||
}; | ||
} | ||
}]); | ||
function InstantSearch(props) { | ||
var _this; | ||
@@ -70,11 +89,7 @@ | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(InstantSearch).call(this, props)); | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(InstantSearch)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_this), "isUnmounting", false); | ||
_defineProperty(_assertThisInitialized(_this), "aisManager", createInstantSearchManager({ | ||
var instantSearchManager = createInstantSearchManager({ | ||
indexName: _this.props.indexName, | ||
@@ -85,19 +100,18 @@ searchClient: _this.props.searchClient, | ||
stalledSearchDelay: _this.props.stalledSearchDelay | ||
})); | ||
_defineProperty(_assertThisInitialized(_this), "isControlled", isControlled(_this.props)); | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
contextValue: { | ||
onInternalStateUpdate: _this.onWidgetsInternalStateUpdate.bind(_assertThisInitialized(_this)), | ||
createHrefForState: _this.createHrefForState.bind(_assertThisInitialized(_this)), | ||
onSearchForFacetValues: _this.onSearchForFacetValues.bind(_assertThisInitialized(_this)), | ||
onSearchStateChange: _this.onSearchStateChange.bind(_assertThisInitialized(_this)), | ||
onSearchParameters: _this.onSearchParameters.bind(_assertThisInitialized(_this)), | ||
store: _this.aisManager.store, | ||
widgetsManager: _this.aisManager.widgetsManager, | ||
mainTargetedIndex: _this.props.indexName | ||
} | ||
}); | ||
var contextValue = { | ||
store: instantSearchManager.store, | ||
widgetsManager: instantSearchManager.widgetsManager, | ||
mainTargetedIndex: _this.props.indexName, | ||
onInternalStateUpdate: _this.onWidgetsInternalStateUpdate.bind(_assertThisInitialized(_this)), | ||
createHrefForState: _this.createHrefForState.bind(_assertThisInitialized(_this)), | ||
onSearchForFacetValues: _this.onSearchForFacetValues.bind(_assertThisInitialized(_this)), | ||
onSearchStateChange: _this.onSearchStateChange.bind(_assertThisInitialized(_this)), | ||
onSearchParameters: _this.onSearchParameters.bind(_assertThisInitialized(_this)) | ||
}; | ||
_this.state = { | ||
isControlled: isControlled(_this.props), | ||
instantSearchManager: instantSearchManager, | ||
contextValue: contextValue | ||
}; | ||
return _this; | ||
@@ -109,31 +123,22 @@ } | ||
value: function componentDidUpdate(prevProps) { | ||
var nextIsControlled = isControlled(this.props); | ||
var prevIsControlled = isControlled(prevProps); | ||
if (!this.isControlled && nextIsControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being uncontrolled to controlled"); | ||
if (prevIsControlled && !this.state.isControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being controlled to uncontrolled"); | ||
} | ||
if (this.isControlled && !nextIsControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being controlled to uncontrolled"); | ||
if (!prevIsControlled && this.state.isControlled) { | ||
throw new Error("You can't switch <InstantSearch> from being uncontrolled to controlled"); | ||
} | ||
/* | ||
* Clear cache when `refresh` changes to `true`. | ||
* Prevents users to always clear the cache on render if they forget to revert it to `false`. | ||
*/ | ||
if (this.props.refresh !== prevProps.refresh && this.props.refresh) { | ||
this.aisManager.clearCache(); | ||
this.state.instantSearchManager.clearCache(); | ||
} | ||
if (this.isControlled) { | ||
this.aisManager.onExternalStateUpdate(this.props.searchState); | ||
} | ||
if (prevProps.indexName !== this.props.indexName) { | ||
this.aisManager.updateIndex(this.props.indexName); | ||
this.state.instantSearchManager.updateIndex(this.props.indexName); | ||
} | ||
if (prevProps.searchClient !== this.props.searchClient) { | ||
this.aisManager.updateClient(this.props.searchClient); | ||
this.state.instantSearchManager.updateClient(this.props.searchClient); | ||
} | ||
@@ -145,3 +150,3 @@ } | ||
this.isUnmounting = true; | ||
this.aisManager.skipSearch(); | ||
this.state.instantSearchManager.skipSearch(); | ||
} | ||
@@ -151,4 +156,4 @@ }, { | ||
value: function createHrefForState(searchState) { | ||
searchState = this.aisManager.transitionState(searchState); | ||
return this.isControlled && this.props.createURL ? this.props.createURL(searchState, this.getKnownKeys()) : '#'; | ||
searchState = this.state.instantSearchManager.transitionState(searchState); | ||
return this.state.isControlled && this.props.createURL ? this.props.createURL(searchState, this.getKnownKeys()) : '#'; | ||
} | ||
@@ -158,7 +163,7 @@ }, { | ||
value: function onWidgetsInternalStateUpdate(searchState) { | ||
searchState = this.aisManager.transitionState(searchState); | ||
searchState = this.state.instantSearchManager.transitionState(searchState); | ||
this.onSearchStateChange(searchState); | ||
if (!this.isControlled) { | ||
this.aisManager.onExternalStateUpdate(searchState); | ||
if (!this.state.isControlled) { | ||
this.state.instantSearchManager.onExternalStateUpdate(searchState); | ||
} | ||
@@ -185,3 +190,3 @@ } | ||
value: function onSearchForFacetValues(searchState) { | ||
this.aisManager.onSearchForFacetValues(searchState); | ||
this.state.instantSearchManager.onSearchForFacetValues(searchState); | ||
} | ||
@@ -191,3 +196,3 @@ }, { | ||
value: function getKnownKeys() { | ||
return this.aisManager.getWidgetsIds(); | ||
return this.state.instantSearchManager.getWidgetsIds(); | ||
} | ||
@@ -205,11 +210,2 @@ }, { | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(nextProps, prevState) { | ||
return { | ||
contextValue: _objectSpread({}, prevState.contextValue, { | ||
mainTargetedIndex: nextProps.indexName | ||
}) | ||
}; | ||
} | ||
}]); | ||
@@ -216,0 +212,0 @@ |
{ | ||
"name": "react-instantsearch-core", | ||
"version": "6.0.0-beta.0", | ||
"version": "6.0.0-beta.1", | ||
"description": "⚡ Lightning-fast search for React, by Algolia", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1941960
18551