Add Vue watch mixin to update a variable on changes to another.

To be used where adding .sync to props is not convenient for
one reason or another.
This commit is contained in:
D. Berge
2023-11-13 20:21:37 +01:00
parent efe64f0a8c
commit 53e7a06a18

View File

@@ -0,0 +1,14 @@
import { deepCompare } from './utils';
function setIfDifferent(propsLocals) {
return Object.fromEntries(Object.entries(propsLocals).map( ([prop, local]) => [
local,
() => {
if (!deepCompare(this[prop], this[local])){
this[local] = structuredClone(this[prop]);
}
}
]));
}
export default setIfDifferent;