@searchspring/snap-store-mobx
Advanced tools
Comparing version 0.45.1 to 0.46.0
@@ -117,5 +117,5 @@ "use strict"; | ||
if (!this.state.locks.terms.locked) { | ||
this.terms = new Stores_2.AutocompleteTermStore(this.services, data.autocomplete || {}, data.pagination || {}, function () { | ||
this.terms = new Stores_2.AutocompleteTermStore(this.services, data.autocomplete || {}, data.pagination || {}, data.search || {}, function () { | ||
_this.resetTerms(); | ||
}, this.state); | ||
}, this.state, this.config); | ||
// only lock if there was data | ||
@@ -122,0 +122,0 @@ data.autocomplete && this.state.locks.terms.lock(); |
import type { UrlManager } from '@searchspring/snap-url-manager'; | ||
import type { AutocompleteStateStore } from './AutocompleteStateStore'; | ||
import type { StoreServices } from '../../types'; | ||
import type { AutocompleteResponseModelAllOfAutocomplete, SearchResponseModelPagination } from '@searchspring/snapi-types'; | ||
import type { AutocompleteStoreConfig, StoreServices } from '../../types'; | ||
import type { AutocompleteResponseModelAllOfAutocomplete, SearchResponseModelPagination, SearchResponseModelSearch } from '@searchspring/snapi-types'; | ||
export declare class AutocompleteTermStore extends Array<Term> { | ||
static get [Symbol.species](): ArrayConstructor; | ||
constructor(services: StoreServices, autocomplete: AutocompleteResponseModelAllOfAutocomplete, paginationData: SearchResponseModelPagination, resetTerms: () => void, rootState: AutocompleteStateStore); | ||
constructor(services: StoreServices, autocomplete: AutocompleteResponseModelAllOfAutocomplete, paginationData: SearchResponseModelPagination, search: SearchResponseModelSearch, resetTerms: () => void, rootState: AutocompleteStateStore, config: AutocompleteStoreConfig); | ||
} | ||
@@ -9,0 +9,0 @@ export declare class Term { |
@@ -31,17 +31,26 @@ "use strict"; | ||
__extends(AutocompleteTermStore, _super); | ||
function AutocompleteTermStore(services, autocomplete, paginationData, resetTerms, rootState) { | ||
var _a; | ||
function AutocompleteTermStore(services, autocomplete, paginationData, search, resetTerms, rootState, config) { | ||
var _a, _b; | ||
var suggestions = __spreadArray([], ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.alternatives) ? autocomplete.alternatives : []).map(function (term) { return term.text; }), true); | ||
if ((_a = autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.suggested) === null || _a === void 0 ? void 0 : _a.text) { | ||
// a suggestion for query | ||
suggestions.unshift(autocomplete.suggested.text); | ||
if ((_a = config.settings) === null || _a === void 0 ? void 0 : _a.integratedSpellCorrection) { | ||
if ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.correctedQuery) && (search === null || search === void 0 ? void 0 : search.query) && autocomplete.correctedQuery.toLowerCase() != search.query.toLowerCase()) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
} | ||
(search === null || search === void 0 ? void 0 : search.query) && suggestions.unshift(search.query); | ||
} | ||
else if ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.correctedQuery) && paginationData.totalResults) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
else { | ||
if ((_b = autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.suggested) === null || _b === void 0 ? void 0 : _b.text) { | ||
// a suggestion for query | ||
suggestions.unshift(autocomplete.suggested.text); | ||
} | ||
else if ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.correctedQuery) && paginationData.totalResults) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
} | ||
else if ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.query) && paginationData.totalResults) { | ||
// there were no suggestions or corrections, | ||
suggestions.unshift(autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.query); | ||
} | ||
} | ||
else if ((autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.query) && paginationData.totalResults) { | ||
// there were no suggestions or corrections, | ||
suggestions.unshift(autocomplete === null || autocomplete === void 0 ? void 0 : autocomplete.query); | ||
} | ||
var terms = []; | ||
@@ -48,0 +57,0 @@ suggestions.map(function (term, index) { |
@@ -86,5 +86,5 @@ import { makeObservable, observable } from 'mobx'; | ||
if (!this.state.locks.terms.locked) { | ||
this.terms = new AutocompleteTermStore(this.services, data.autocomplete || {}, data.pagination || {}, () => { | ||
this.terms = new AutocompleteTermStore(this.services, data.autocomplete || {}, data.pagination || {}, data.search || {}, () => { | ||
this.resetTerms(); | ||
}, this.state); | ||
}, this.state, this.config); | ||
// only lock if there was data | ||
@@ -91,0 +91,0 @@ data.autocomplete && this.state.locks.terms.lock(); |
import type { UrlManager } from '@searchspring/snap-url-manager'; | ||
import type { AutocompleteStateStore } from './AutocompleteStateStore'; | ||
import type { StoreServices } from '../../types'; | ||
import type { AutocompleteResponseModelAllOfAutocomplete, SearchResponseModelPagination } from '@searchspring/snapi-types'; | ||
import type { AutocompleteStoreConfig, StoreServices } from '../../types'; | ||
import type { AutocompleteResponseModelAllOfAutocomplete, SearchResponseModelPagination, SearchResponseModelSearch } from '@searchspring/snapi-types'; | ||
export declare class AutocompleteTermStore extends Array<Term> { | ||
static get [Symbol.species](): ArrayConstructor; | ||
constructor(services: StoreServices, autocomplete: AutocompleteResponseModelAllOfAutocomplete, paginationData: SearchResponseModelPagination, resetTerms: () => void, rootState: AutocompleteStateStore); | ||
constructor(services: StoreServices, autocomplete: AutocompleteResponseModelAllOfAutocomplete, paginationData: SearchResponseModelPagination, search: SearchResponseModelSearch, resetTerms: () => void, rootState: AutocompleteStateStore, config: AutocompleteStoreConfig); | ||
} | ||
@@ -9,0 +9,0 @@ export declare class Term { |
@@ -6,16 +6,25 @@ import { observable, makeObservable } from 'mobx'; | ||
} | ||
constructor(services, autocomplete, paginationData, resetTerms, rootState) { | ||
constructor(services, autocomplete, paginationData, search, resetTerms, rootState, config) { | ||
const suggestions = [...(autocomplete?.alternatives ? autocomplete.alternatives : []).map((term) => term.text)]; | ||
if (autocomplete?.suggested?.text) { | ||
// a suggestion for query | ||
suggestions.unshift(autocomplete.suggested.text); | ||
if (config.settings?.integratedSpellCorrection) { | ||
if (autocomplete?.correctedQuery && search?.query && autocomplete.correctedQuery.toLowerCase() != search.query.toLowerCase()) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
} | ||
search?.query && suggestions.unshift(search.query); | ||
} | ||
else if (autocomplete?.correctedQuery && paginationData.totalResults) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
else { | ||
if (autocomplete?.suggested?.text) { | ||
// a suggestion for query | ||
suggestions.unshift(autocomplete.suggested.text); | ||
} | ||
else if (autocomplete?.correctedQuery && paginationData.totalResults) { | ||
// the query was corrected | ||
suggestions.unshift(autocomplete.correctedQuery); | ||
} | ||
else if (autocomplete?.query && paginationData.totalResults) { | ||
// there were no suggestions or corrections, | ||
suggestions.unshift(autocomplete?.query); | ||
} | ||
} | ||
else if (autocomplete?.query && paginationData.totalResults) { | ||
// there were no suggestions or corrections, | ||
suggestions.unshift(autocomplete?.query); | ||
} | ||
const terms = []; | ||
@@ -22,0 +31,0 @@ suggestions.map((term, index) => terms.push(new Term(services, { |
{ | ||
"name": "@searchspring/snap-store-mobx", | ||
"version": "0.45.1", | ||
"version": "0.46.0", | ||
"description": "Snap MobX Store", | ||
@@ -23,8 +23,8 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@searchspring/snap-toolbox": "^0.45.1", | ||
"@searchspring/snap-toolbox": "^0.46.0", | ||
"mobx": "^6.6.1" | ||
}, | ||
"devDependencies": { | ||
"@searchspring/snap-client": "^0.45.1", | ||
"@searchspring/snap-url-manager": "^0.45.1" | ||
"@searchspring/snap-client": "^0.46.0", | ||
"@searchspring/snap-url-manager": "^0.46.0" | ||
}, | ||
@@ -35,3 +35,3 @@ "sideEffects": false, | ||
], | ||
"gitHead": "345e457a841f882f7162d032528313f5623f388d" | ||
"gitHead": "b92fc5fe0dd848d4ccdd6242dce7a70be53cb99c" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
296451
5541
+ Added@searchspring/snap-toolbox@0.46.0(transitive)
- Removed@searchspring/snap-toolbox@0.45.1(transitive)