This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { readonly, ref } from 'vue';
|
||||
import { readonly, Ref, ref } from 'vue';
|
||||
|
||||
/**
|
||||
* Random labels as a library function.
|
||||
* Will return a random label from the given options.
|
||||
* Calling the `update` function that is returned will pick a new label.
|
||||
* @param options
|
||||
*/
|
||||
export function randomLabel(options: string[]) {
|
||||
const label = ref<string>();
|
||||
const randomLabel = () => {
|
||||
@@ -12,7 +18,11 @@ export function randomLabel(options: string[]) {
|
||||
label.value = randomLabel();
|
||||
|
||||
return {
|
||||
label: readonly(label),
|
||||
update: () => (label.value = randomLabel()),
|
||||
// This type refinement is proper as the `undefined` value can never happen from this point onwards
|
||||
label: readonly(label as Ref<string>),
|
||||
// Updates the returned `label` with a new randomly chosen one
|
||||
update() {
|
||||
label.value = randomLabel();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user