You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/ui-v2/app/services/lazy-proxy.js

33 lines
928 B

import Service from '@ember/service';
import { get } from '@ember/object';
export default Service.extend({
shouldProxy: function(content, method) {
return false;
},
init: function() {
this._super(...arguments);
const content = get(this, 'content');
for (let prop in content) {
if (typeof content[prop] === 'function') {
if (this.shouldProxy(content, prop)) {
this[prop] = function() {
const cb = this.execute(content, prop);
if (typeof cb.then !== 'undefined') {
return cb.then(method => {
return method.apply(this, arguments);
});
} else {
return cb.apply(this, arguments);
}
};
} else if (typeof this[prop] !== 'function') {
this[prop] = function() {
return content[prop](...arguments);
};
}
}
}
},
});