UNPKG

vue-instantsearch

Version:

👀 Lightning-fast Algolia search for Vue apps

2 lines (1 loc) • 2.2 kB
import{_ as t}from"@swc/helpers/_/_define_property";import{_objectSpread as e}from"../util/polyfills.js";import"@swc/helpers/_/_type_of";import"vue";import{warn as n}from"../util/warn.js";var i=function(){var i,s=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).connector,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t(i={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 "<'.concat(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 s){if(this.factory=s(this.updateState,function(){}),this.widget=e(this.factory(this.widgetParams),a),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!==s&&n("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])}),t(i,"watch",{widgetParams:{handler:function(t){this.state=null,this.getParentIndex().removeWidgets([this.widget]),this.widget=e(this.factory(t),a),this.getParentIndex().addWidgets([this.widget])},deep:!0}}),t(i,"methods",{updateState:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(arguments.length>1?arguments[1]:void 0)||(this.state=t)}}),i};export{i as createWidgetMixin};