UNPKG

vue-instantsearch-ssr

Version:

👀 Lightning-fast Algolia search for Vue apps

3 lines (2 loc) • 1.92 kB
import"../util/vue-compat/index-vue2.js";import{warn as t}from"../util/warn.js";var e=function(e){var n;void 0===e&&(e={});var i=e.connector;return(n={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 i){if(this.factory=i(this.updateState,function(){}),this.widget=this.factory(this.widgetParams),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!==i&&t("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")}}).beforeDestroy=function(){this.widget&&this.getParentIndex().removeWidgets([this.widget])},n.watch={widgetParams:{handler:function(t){this.state=null,this.getParentIndex().removeWidgets([this.widget]),this.widget=this.factory(t),this.getParentIndex().addWidgets([this.widget])},deep:!0}},n.methods={updateState:function(t,e){void 0===t&&(t={}),e||(this.state=t)}},n};export{e as createWidgetMixin}; //# sourceMappingURL=widget.js.map