Skip to content

Commit

Permalink
feat: simplified api singleton management
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 3, 2024
1 parent 8ca6949 commit 15955cb
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 29 deletions.
7 changes: 2 additions & 5 deletions packages/mtb/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {
defineNuxtModule,
} from '@nuxt/kit';

// Module options TypeScript interface definition
export interface ModuleOptions {}

export default defineNuxtModule<ModuleOptions>({
export default defineNuxtModule({
meta: {
name: '@dnpm-dip/mtb',
configKey: 'mtb',
Expand Down Expand Up @@ -40,7 +37,7 @@ export default defineNuxtModule<ModuleOptions>({

addImportsSources({
from: resolver.resolve('./runtime/composables/index'),
imports: ['useAPIClient', 'useMTBAPIClient'],
imports: ['useMTBAPIClient'],
});

addPlugin(resolver.resolve('./runtime/plugins/api'));
Expand Down
4 changes: 0 additions & 4 deletions packages/mtb/src/runtime/composables/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { APIClient } from '@dnpm-dip/core';
import { useNuxtApp } from '#imports';
import type { MTBAPIClient } from '../core/api-client';

export function useAPIClient() {
return useNuxtApp().$api as APIClient;
}
export function useMTBAPIClient() {
return useNuxtApp().$mtbApi as MTBAPIClient;
}
1 change: 0 additions & 1 deletion packages/mtb/src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export {
useAPIClient,
useMTBAPIClient,
} from './api-client';
6 changes: 2 additions & 4 deletions packages/mtb/src/runtime/plugins/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { APIClient } from '@dnpm-dip/core';
import { MTBAPIClient } from '../core/api-client';
import { useAPIClient } from '../composables';
import { defineNuxtPlugin } from '#app';

export default defineNuxtPlugin({
enforce: 'post',
async setup(nuxt) {
const baseClient = useAPIClient();

const client = new MTBAPIClient(baseClient);
const client = new MTBAPIClient(nuxt.$api as APIClient);

return {
provide: {
Expand Down
9 changes: 3 additions & 6 deletions packages/rd/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ import {
addImportsSources, addPlugin, createResolver, defineNuxtModule,
} from '@nuxt/kit';

// Module options TypeScript interface definition
export interface ModuleOptions {}

export default defineNuxtModule<ModuleOptions>({
export default defineNuxtModule({
meta: {
name: '@dnpm-dip/rare-diseases',
name: '@dnpm-dip/rd',
configKey: 'rd',
},
// Default configuration options of the Nuxt module
Expand Down Expand Up @@ -40,7 +37,7 @@ export default defineNuxtModule<ModuleOptions>({

addImportsSources({
from: resolver.resolve('./runtime/composables/index'),
imports: ['useAPIClient', 'useRDAPIClient'],
imports: ['useRDAPIClient'],
});

addPlugin(resolver.resolve('./runtime/plugins/api'));
Expand Down
4 changes: 0 additions & 4 deletions packages/rd/src/runtime/composables/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { APIClient } from '@dnpm-dip/core';
import { useNuxtApp } from '#imports';
import type { RDAPIClient } from '../core/api-client';

export function useAPIClient() {
return useNuxtApp().$api as APIClient;
}
export function useRDAPIClient() {
return useNuxtApp().$rdApi as RDAPIClient;
}
1 change: 0 additions & 1 deletion packages/rd/src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export {
useAPIClient,
useRDAPIClient,
} from './api-client';
6 changes: 2 additions & 4 deletions packages/rd/src/runtime/plugins/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { APIClient } from '@dnpm-dip/core';
import { RDAPIClient } from '../core/api-client';
import { defineNuxtPlugin } from '#app';
import { useAPIClient } from '../composables';

export default defineNuxtPlugin({
enforce: 'post',
async setup(nuxt) {
const baseClient = useAPIClient();

const client = new RDAPIClient(baseClient);
const client = new RDAPIClient(nuxt.$api as APIClient);

return {
provide: {
Expand Down

0 comments on commit 15955cb

Please sign in to comment.