woodpecker/web/src/compositions/useInjectProvide.ts
[X] b4d89a1cce
Add ability to trigger manual builds (#1156)
closes #83 
closes #240 

Co-authored-by: Anbraten <anton@ju60.de>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2022-09-27 11:05:00 +02:00

20 lines
521 B
TypeScript

import { inject as vueInject, provide as vueProvide, Ref } from 'vue';
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 {
return vueProvide(key, value);
}