Files
directus/packages/shared/src/composables/use-sync.ts
Nitwel ce8401b940 Move some compositons, utils and types to shared (#8059)
* move composables, types and utils to shared

* move composables, utils and types to shared

* expose utils and composables in extensionsSDK

* fix missing dependencies

* Sort index.ts exports

* Do the thing

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
2021-09-15 16:41:08 -04:00

17 lines
329 B
TypeScript

import { computed, Ref } from 'vue';
export function useSync<T, K extends keyof T & string, E extends (event: `update:${K}`, ...args: any[]) => void>(
props: T,
key: K,
emit: E
): Ref<T[K]> {
return computed<T[K]>({
get() {
return props[key];
},
set(newVal) {
emit(`update:${key}` as const, newVal);
},
});
}