vue-instantsearch
Version:
👀 Lightning-fast Algolia search for Vue apps
3 lines (2 loc) • 2.41 kB
JavaScript
import{Vue2 as t}from"./vue-compat/index-vue2.js";import{warn as e}from"./warn.js";import n from"instantsearch.js/es/index.js";function r(e,n){void 0===n&&(n={});var r=n.mixins;void 0===r&&(r=[]);var o,s={serverPrefetch:void 0,fetch:void 0,_base:void 0,name:"ais-ssr-root-component"};return s.router=e.$router,s.store=e.$store,(o=new(e.$vnode?e.$vnode.componentOptions.Ctor.extend(s):t.component(s.name,Object.assign({},e.$options,s)))({propsData:e.$options.propsData,mixins:[].concat(r)})).$slots=e.$slots,o.$root=e.$root,o.$options.serverPrefetch=[],o}function o(t,r){var o,s=n(t);return s.findResultsState=function(t){var e,n,i=t.component,a=t.renderToString;if(!a)throw new Error("findResultsState requires `renderToString: (component) => Promise<string>` in the first argument.");return Promise.resolve().then(function(){e=r(i,{mixins:[{beforeCreate:function(){i.$nuxt&&(this.$nuxt=i.$nuxt)},created:function(){(n=this.instantsearch).start(),n.started=!1}}]})}).then(function(){return a(e)}).then(function(){return t=n.mainHelper,new Promise(function(e,n){t.searchOnlyWithDerivedHelpers(),t.derivedHelpers[0].on("result",function(){e()}),t.derivedHelpers.forEach(function(t){return t.on("error",function(t){n(t)})})});var t}).then(function(){return o={},function t(e,n){return n(e),e.getWidgets().forEach(function(e){"ais.index"===e.$$type&&(n(e),t(e,n))})}(n.mainIndex,function(t){var e=t.getResults(),n=e._state,r=e._rawResults;o[t.getIndexId()]={state:Object.keys(n).reduce(function(t,e){return t[e]=n[e],t},{}),results:r}}),s.hydrate(o),s.getState()})},s.getState=function(){if(!o)throw new Error("You need to wait for findResultsState to finish");return o},s.__forceRender=function(t,e){var n=e.getResults();if(null!==n){var r=n._state,o=e.getHelper();o.state=r,t.render({helper:o,results:n,scopedResults:e.getScopedResults(),parent:e,state:r,templatesConfig:{},createURL:e.createURL,instantSearchInstance:s,searchMetadata:{isSearchStalled:!1}})}},s.hydrate=function(t){t?(s._initialResults=t,s.start(),s.started=!1):e("The result of `findResultsState()` needs to be passed to `hydrate()`.")},s}function s(t){void 0===t&&(t={});var e=t.$cloneComponent;void 0===e&&(e=r);var n=o(t,e);return{provide:function(){return{$_ais_ssrInstantSearchInstance:this.instantsearch}},data:function(){return{instantsearch:n}}}}export{s as createServerRootMixin};
//# sourceMappingURL=createServerRootMixin.js.map