Created
March 11, 2016 21:30
-
-
Save poteto/37b71a01e2ff9d062628 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 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
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