mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 08:17:09 +00:00
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:
14
lib/www/client/source/src/lib/watcher-mixin.js
Normal file
14
lib/www/client/source/src/lib/watcher-mixin.js
Normal 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;
|
||||
Reference in New Issue
Block a user