mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
avoid async report pattern and replace with simpler hijack
This commit is contained in:
@ -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() {
|
||||
|
Reference in New Issue
Block a user