Skip to content

Instantly share code, notes, and snippets.

@danlourenco
Forked from pwfisher/dynamic-alias.js
Created August 2, 2016 20:20
Show Gist options
  • Save danlourenco/bc22045e03cbbcd41fc8c32444fe2889 to your computer and use it in GitHub Desktop.
Save danlourenco/bc22045e03cbbcd41fc8c32444fe2889 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment