Skip to content

Instantly share code, notes, and snippets.

@bortevik
Last active May 2, 2017 11:21
Show Gist options
  • Save bortevik/9bd542270cd3b0de0b14feee2a975a04 to your computer and use it in GitHub Desktop.
Save bortevik/9bd542270cd3b0de0b14feee2a975a04 to your computer and use it in GitHub Desktop.
Pure computed
pure(...args) {
const f = args.pop();
return Ember.computed(...args, function() {
const values = args.map(arg => {
if (arg.match(/@each/)) {
const segments = arg.split('.@each.');
return this.get(segments[0]).map(v => v.get(segments[1]));
} else if (arg.match(/\[\]/)) {
const segments = arg.split('.[]');
return this.get(segments[0]);
} else {
return this.get(arg);
}
});
return f(...values);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment