import Ember from 'ember';

export default Ember.Component.extend({
  logBinding: 'job.log',

  didReceiveAttrs: function(options) {
    this._super(...arguments);

    if(options.oldAttrs && options.oldAttrs.job && options.oldAttrs.job.value) {
      this.teardownLog(options.oldAttrs.job.value);
    }

    if(options.newAttrs && options.newAttrs.job && options.newAttrs.job.value) {
      this.setupLog(options.newAttrs.job.value);
    }
  },

  teardownLog(job) {
    job.unsubscribe();
  },

  setupLog(job) {
    job.get('log').fetch();
    job.subscribe();
  }
});

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();
  }
});

Fix logs displaying when a restart happens
Fix logs displaying when a restart happens

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.
