2023-07-02 10:47:36 +00:00
|
|
|
import { inject as vueInject, InjectionKey, provide as vueProvide, Ref } from 'vue';
|
2022-09-27 09:05:00 +00:00
|
|
|
|
|
|
|
import { Repo } from '~/lib/api/types';
|
|
|
|
|
|
|
|
export type InjectKeys = {
|
|
|
|
repo: Ref<Repo>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function inject<T extends keyof InjectKeys>(key: T): InjectKeys[T] {
|
|
|
|
const value = vueInject<InjectKeys[T]>(key);
|
|
|
|
if (value === undefined) {
|
|
|
|
throw new Error(`Please provide a value for ${key}`);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function provide<T extends keyof InjectKeys>(key: T, value: InjectKeys[T]): void {
|
2023-07-02 10:47:36 +00:00
|
|
|
return vueProvide(key, value as T extends InjectionKey<infer V> ? V : InjectKeys[T]);
|
2022-09-27 09:05:00 +00:00
|
|
|
}
|