UNPKG

vue-instantsearch

Version:

👀 Lightning-fast Algolia search for Vue apps

3 lines (2 loc) • 2 kB
import{_objectSpread as t}from"../util/polyfills.js";import"../util/vue-compat/index-vue3.js";import{warn as e}from"../util/warn.js";var n=function(n,i){var s;void 0===n&&(n={});var a=n.connector;return void 0===i&&(i={}),(s={inject:{instantSearchInstance:{from:"$_ais_instantSearchInstance",default:function(){var t=this.$options._componentTag;throw new TypeError('It looks like you forgot to wrap your Algolia search component "<'+t+'>" inside of an "<ais-instant-search>" component.')}},getParentIndex:{from:"$_ais_getParentIndex",default:function(){var t=this;return function(){return t.instantSearchInstance.mainIndex}}}},data:function(){return{state:null}},created:function(){if("function"==typeof a){if(this.factory=a(this.updateState,function(){}),this.widget=t(this.factory(this.widgetParams),i),this.getParentIndex().addWidgets([this.widget]),this.instantSearchInstance._initialResults&&!this.instantSearchInstance.started){if("function"!=typeof this.instantSearchInstance.__forceRender)throw new Error("You are using server side rendering with <ais-instant-search> instead of <ais-instant-search-ssr>.");this.instantSearchInstance.__forceRender(this.widget,this.getParentIndex())}}else!0!==a&&e("You are using the InstantSearch widget mixin, but didn't provide a connector.\nWhile this is technically possible, and will give you access to the Helper,\nit's not the recommended way of making custom components.\n\nIf you want to disable this message, pass { connector: true } to the mixin.\n\nRead more on using connectors: https://alg.li/vue-custom")}}).beforeUnmount=function(){this.widget&&this.getParentIndex().removeWidgets([this.widget])},s.watch={widgetParams:{handler:function(e){this.state=null,this.getParentIndex().removeWidgets([this.widget]),this.widget=t(this.factory(e),i),this.getParentIndex().addWidgets([this.widget])},deep:!0}},s.methods={updateState:function(t,e){void 0===t&&(t={}),e||(this.state=t)}},s};export{n as createWidgetMixin}; //# sourceMappingURL=widget.js.map