Skip to content

Instantly share code, notes, and snippets.

@pwfisher
Last active August 2, 2016 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pwfisher/283716ad9898c7fc8101 to your computer and use it in GitHub Desktop.
Save pwfisher/283716ad9898c7fc8101 to your computer and use it in GitHub Desktop.
Implementation of the missing "Ember.computed.dynamicAlias"
import Ember from 'ember';
// @see http://emberjs.jsbin.com/beboga/edit?js,output
export default function dynamicAlias(target, keyKey) {
var prefix = target ? `${target}.` : '';
var dynamicAliasKey = `${prefix}${keyKey}_alias`;
return Ember.computed(function() {
var key = `${prefix}${this.get(keyKey)}`;
Ember.defineProperty(this, dynamicAliasKey, Ember.computed.alias(key));
return this.get(key);
}).property(keyKey, dynamicAliasKey);
}
@webark
Copy link

webark commented Feb 18, 2016

didn't need the target in the alias property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment