import { computed, type Ref, shallowRef } from "vue"; export const writable = (upstream: () => T) => { // it's a bit weird, but this essentially guarantees that the ref gets reset // immediately as expected. this also gets around the double-calling that // using `watch` would cause. const computable = computed(() => shallowRef(upstream())); return computed({ get() { return computable.value.value; }, set(next) { computable.value.value = next; }, }); };