Last active
May 2, 2017 11:21
-
-
Save bortevik/9bd542270cd3b0de0b14feee2a975a04 to your computer and use it in GitHub Desktop.
Pure computed
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
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