Skip to content

Instantly share code, notes, and snippets.

@patricklx
Created November 15, 2014 17:42
Show Gist options
  • Save patricklx/f724c080cd6843d223df to your computer and use it in GitHub Desktop.
Save patricklx/f724c080cd6843d223df to your computer and use it in GitHub Desktop.
var a_slice = [].slice;
Ember.ComputedProperty.prototype.chain = function(method){
var chainedCP, dependentKey, args, func, cp = this;
dependentKey = Ember.guidFor(cp) + '-chain';
args = [dependentKey].concat(a_slice.call(arguments,1));
if (typeof method === 'string') {
method = Ember.computed[method];
}
chainedCP = method.apply(null,args);
func = chainedCP.func;
chainedCP.func = function (propertyName) {
if (!this.__ember_meta__.cacheMeta[propertyName+'-chain']) {
defineProperty(this, dependentKey, cp);
this.__ember_meta__.cacheMeta[propertyName+'-chain'] = true;
}
return func.apply(this, arguments);
};
return chainedCP;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment