vue-instantsearch icon indicating copy to clipboard operation
vue-instantsearch copied to clipboard

feat: add experimental composition APIs

Open eunjae-lee opened this issue 4 years ago • 8 comments
trafficstars

Summary

This PR adds experimental composition APIs.

For now, useConfigure, useRefinementList, useSearchBox, and useConnector are implemented.

In case of useRefinementList, I referred to François' PoC with React InstantSearch.

vue 3

<template>
  <div>
    <p>query: {{ searchBox.query }}</p>
  </div>
</template>

<script>
import { EXPERIMENTAL_useSearchBox } from 'vue-instantsearch/vue3/es';

export default {
  setup() {
    return { searchBox: EXPERIMENTAL_useSearchBox() };
  }
}

vue 2

yarn add @vue/composition-api
# or
npm install @vue/composition-api
// main.js
import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';

Vue.use(VueCompositionAPI);
// Child.vue

<template>
  <div>
    <p>query: {{ searchBox.query }}</p>
  </div>
</template>

<script>
import { EXPERIMENTAL_useSearchBox } from 'vue-instantsearch/vue2/es/compositions';
// Import composition APIs from the path above.
// The rest still remain as `import xxx from 'vue-instantsearch'`.

export default {
  setup() {
    return { searchBox: EXPERIMENTAL_useSearchBox() };
  }
}

eunjae-lee avatar Sep 01 '21 14:09 eunjae-lee

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Sep 01 '21 14:09 codesandbox-ci[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Sep 01 '21 14:09 codesandbox-ci[bot]

I thought you could use the composition api in vue 2 with @vue/composition-api or something like that?

Haroenv avatar Sep 01 '21 14:09 Haroenv

I thought you could use the composition api in vue 2 with @vue/composition-api or something like that?

You're right. I haven't figured out how to accept that optional dependency for vue 2 yet. So I'm just starting with Vue 3 for now.

eunjae-lee avatar Sep 01 '21 15:09 eunjae-lee

Bumping this topic as it looks great!

I just released an Algolia module for Nuxt 3 -> https://algolia-nc.netlify.app/ And I was looking to include vue-instantsearch there as well.

If you can finish this PR and make these components Vue 3 compatible, I can try to import them to the module as well so that the users can use your components in Nuxt 3 as well 😉

Baroshem avatar Jan 05 '22 12:01 Baroshem

@Baroshem, the components are already vue 3 compatible if you import from vue-instantsearch/vue3, but that's indeed not really properly documented yet

Haroenv avatar Jan 05 '22 13:01 Haroenv

@Haroenv I see. I will try then to use them in the module so that they can be imported into the Nuxt 3 right now. Thanks for claryfing!

Baroshem avatar Jan 05 '22 21:01 Baroshem

Hi @Haroenv

I tried yesterday to import vue-instantsearch/vue3 but failed after many attempts to fix the errors. I had issues with

  • "type": "module" in package.json (it was not there so I had to add manually)
  • directory imports
  • external packages imports (instantsearch.js).

I have very little experience with the source code of vue-instantsearch so I am not sure if the changes I was doing are even correct.

Could you please try to install vue-instantseach/vue3 on fresh Nuxt 3 project and see how it works for you?

Baroshem avatar Jan 10 '22 08:01 Baroshem