@stackoverfloweth/vue-compositions
Version:
A collection of reusable vue compositions.
27 lines • 657 B
JavaScript
import { computed } from 'vue';
/**
* patch a specific property of an object ref
* @param source an object ref
* @param key the key to patch
* @returns
* @example
* const source = ref({ a: 1, b: 2 })
* const a = usePatchRef(source, 'a')
* a.value = 3
* console.log(source.value) // { a: 3, b: 2 }
* console.log(a.value) // 3
*/
export function usePatchRef(source, key) {
return computed({
get() {
return source.value[key];
},
set(value) {
source.value = {
...source.value,
[key]: value,
};
},
});
}
//# sourceMappingURL=usePatchRef.js.map