-
Notifications
You must be signed in to change notification settings - Fork 157
feat: add experimental composition APIs #1052
Conversation
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. |
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. |
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. |
const excludeCompositionsAPI = { | ||
load(id) { | ||
if (id.endsWith('/src/compositions/index.js')) { | ||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import with '/src/compositions/index.js'
gets replaced with an empty string. It's to exclude this line from Vue 2 bundle:
export * from './compositions'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the build script to modify exports is a bit shady and hard to track.
Can we rather have different entry files? (similar to what React is doing)
58618c5
to
b33cb3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I rewrote a bunch of the code, it's best to have someone else review too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense to start introducing the connector Hooks in stacked PRs and to test them a little.
const excludeCompositionsAPI = { | ||
load(id) { | ||
if (id.endsWith('/src/compositions/index.js')) { | ||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the build script to modify exports is a bit shady and hard to track.
Can we rather have different entry files? (similar to what React is doing)
src/compositions/useConnector.js
Outdated
widget = addWidget( | ||
connector, | ||
parent, | ||
isRef(widgetParams) ? widgetParams.value : widgetParams, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have different data types for widgetParams
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Vue 3, you can only listen to changes from refs, not from plain objects, so we accept both a ref and not a ref, depending on if it needs an update.
This part I'm not 100% sure about, maybe it could accept raw props and put in a ref inside useConnector. Would need to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think we should standardize it. (And internally right now we can have an intermediary variable in useConnector
to not have to think about all data types whenever we use the props.)
Bumping this topic as it looks great! I just released an Algolia module for Nuxt 3 -> https://algolia-nc.netlify.app/ 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, the components are already vue 3 compatible if you import from |
@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! |
Hi @Haroenv I tried yesterday to import vue-instantsearch/vue3 but failed after many attempts to fix the errors. I had issues with
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? |
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
vue 2
yarn add @vue/composition-api # or npm install @vue/composition-api