Created
April 26, 2022 13:28
-
-
Save cefn/c4b3ab064c55dd8c05b73092036bb1e9 to your computer and use it in GitHub Desktop.
Possible follow implementation to map named children to named VM properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { computed, ComputedRef } from 'vue'; | |
export function followDescendantsByName< | |
ReactiveParent, | |
ChildKeys extends ReadonlyArray<keyof ReactiveParent>, | |
>(parentSelector: () => ReactiveParent, childKeys: ChildKeys) { | |
return Object.fromEntries( | |
childKeys.map((childKey) => { | |
return [childKey, computed(() => parentSelector()[childKey])]; | |
}), | |
) as { | |
[childKey in ChildKeys[number]]: ComputedRef<ReactiveParent[childKey]>; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment