avoid async report pattern and replace with simpler hijack

This commit is contained in:
Sam
2018-05-16 16:05:03 +10:00
parent 3864091f2d
commit 21e0b7c818
7 changed files with 51 additions and 128 deletions

View File

@ -4,44 +4,12 @@ export default Ember.Mixin.create({
classNameBindings: ["isLoading"],
reports: null,
reportKeys: null,
isLoading: false,
dataSourceNames: "",
init() {
this._super();
this.set("reports", Ember.Object.create());
this.set("reportKeys", []);
this._channels = this.get("dataSources");
this._callback = (report) => {
if (this.get("reportKeys").includes(report.report_key)) {
Em.run.next(() => {
if (this.get("reportKeys").includes(report.report_key)) {
const previousReport = this.get(`reports.${report.report_key}`);
this.set(`reports.${report.report_key}`, this.loadReport(report, previousReport));
this.renderReport();
}
});
}
};
// in case we did not subscribe in time ensure we always grab the
// last thing on the channel
this.subscribe(-2);
},
subscribe(position) {
this._channels.forEach(channel => {
this.messageBus.subscribe(channel, this._callback, position);
});
},
unsubscribe() {
this._channels.forEach(channel => {
this.messageBus.unsubscribe(channel, this._callback);
});
},
@computed("dataSourceNames")
@ -49,21 +17,12 @@ export default Ember.Mixin.create({
return dataSourceNames.split(",").map(source => `/admin/reports/${source}`);
},
willDestroyElement() {
this._super();
this.unsubscribe();
},
didInsertElement() {
this._super();
Ember.run.later(this, function() {
this.fetchReport()
.finally(() => {
this.renderReport();
});
}, 500);
this.fetchReport()
.finally(() => {
this.renderReport();
});
},
didUpdateAttrs() {