2019-02-21 10:36:15 +00:00
|
|
|
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() {
|
2019-05-01 18:09:29 +00:00
|
|
|
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);
|
|
|
|
}
|
2019-02-21 10:36:15 +00:00
|
|
|
};
|
|
|
|
} else if (typeof this[prop] !== 'function') {
|
|
|
|
this[prop] = function() {
|
|
|
|
return content[prop](...arguments);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|