-
-
Save grapho/03776dfc17e0a71814bebb350b98f05a to your computer and use it in GitHub Desktop.
When you don't know what keys to observe for a CP, you can use a macro that determines the keys at runtime.
This file contains 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
export default function makeComputed(objKey) { | |
let keys = Object.keys(get(this, objKey)) | |
.filter((key) => { | |
// choose the keys using some logic | |
}) | |
.map((key) => `${objKey}.${key}`); | |
return computed(...keys, { | |
get() { | |
// do stuff | |
} | |
}) | |
} | |
export default Component.extend({ | |
myObject: { ... }, | |
stuff: makeComputed('myObject') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment