diff --git a/packages/vue/src/composables/useContextFactory/index.test.ts b/packages/vue/src/composables/useContextFactory/index.test.ts index 441a30f..ad26192 100644 --- a/packages/vue/src/composables/useContextFactory/index.test.ts +++ b/packages/vue/src/composables/useContextFactory/index.test.ts @@ -9,7 +9,7 @@ function testFactory( context: ReturnType>, fallback?: Data, ) { - const [inject, provide] = context; + const { inject, provide } = context; const Child = defineComponent({ setup() { @@ -72,7 +72,7 @@ describe('useContextFactory', () => { const childComponent = mount(Child, { global: { - plugins: [app => context[1]('test', app)], + plugins: [app => context.provide('test', app)], }, }); diff --git a/packages/vue/src/composables/useContextFactory/index.ts b/packages/vue/src/composables/useContextFactory/index.ts index e3fec0f..c258d52 100644 --- a/packages/vue/src/composables/useContextFactory/index.ts +++ b/packages/vue/src/composables/useContextFactory/index.ts @@ -7,17 +7,17 @@ import { VueToolsError } from '../..'; * @description A composable that provides a factory for creating context with unique key * * @param {string} name The name of the context - * @returns {readonly [injectContext, provideContext]} The context factory + * @returns {Object} An object with `inject`, `provide` and `key` properties * @throws {VueToolsError} when the context is not provided * * @example - * const [injectContext, provideContext] = useContextFactory('MyContext'); + * const { inject, provide } = useContextFactory('MyContext'); * - * const context = provideContext('Hello World'); - * const value = injectContext(); + * provide('Hello World'); + * const value = inject(); * * @example - * const [injectContext, provideContext] = useContextFactory('MyContext'); + * const { inject: injectContext, provide: provideContext } = useContextFactory('MyContext'); * * // In a plugin * { @@ -44,9 +44,13 @@ export function useContextFactory(name: string) { }; const provideContext = (context: ContextValue, app?: App) => { - (app ? app.provide : provide)(injectionKey, context); + (app?.provide ?? provide)(injectionKey, context); return context; }; - return [injectContext, provideContext] as const; + return { + inject: injectContext, + provide: provideContext, + key: injectionKey, + } } \ No newline at end of file