Skip to content

Commit

Permalink
feat: add composable to support composition api
Browse files Browse the repository at this point in the history
  • Loading branch information
sebtiz13 committed Aug 1, 2023
1 parent 70dde6f commit b1516c7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useKuzzle';
15 changes: 15 additions & 0 deletions src/composables/useKuzzle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getCurrentInstance } from 'vue';
import { Kuzzle } from 'kuzzle-sdk';

export function useKuzzle(): Kuzzle {
const vueInstance = getCurrentInstance();
// Check only in development mode otherwise throw a false error
if (process.env.NODE_ENV !== 'production' && vueInstance === null) {
throw new Error(
`Missing current instance. useKuzzle() must be called inside <script setup> or setup().`,
);
}

const vue = (vueInstance as NonNullable<ReturnType<typeof getCurrentInstance>>).proxy;
return vue.$root.$kuzzle;
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import '../vue-kuzzle.d';
export * from './types';
export * from './composables';
export * from './helpers';
export * from './types';
export * from './plugin';

0 comments on commit b1516c7

Please sign in to comment.