Skip to content

Instantly share code, notes, and snippets.

@poteto
Created March 11, 2016 21:30
Show Gist options
  • Save poteto/37b71a01e2ff9d062628 to your computer and use it in GitHub Desktop.
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.
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