
When a user restarts a job, we should not try fetching the log again. In order to do this I added a guard in job-log component, which checks if attributes changed in didReceiveAttrs callback. If the old job value is the same as the new value, we don't need to do anything.
32 lines
629 B
JavaScript
32 lines
629 B
JavaScript
import Ember from 'ember';
|
|
|
|
export default Ember.Component.extend({
|
|
logBinding: 'job.log',
|
|
|
|
didReceiveAttrs: function(options) {
|
|
this._super(...arguments);
|
|
|
|
let oldJob = options.oldAttrs && options.oldAttrs.job && options.oldAttrs.job.value,
|
|
newJob = options.newAttrs && options.newAttrs.job && options.newAttrs.job.value;
|
|
|
|
if(newJob !== oldJob) {
|
|
if(newJob) {
|
|
this.setupLog(newJob);
|
|
}
|
|
|
|
if(oldJob) {
|
|
this.teardownLog(oldJob);
|
|
}
|
|
}
|
|
},
|
|
|
|
teardownLog(job) {
|
|
job.unsubscribe();
|
|
},
|
|
|
|
setupLog(job) {
|
|
job.get('log').fetch();
|
|
job.subscribe();
|
|
}
|
|
});
|