'use strict';

const Emitter = require('./install/emitter');
const Flow = require('./install/flow');
const {deepMerge} = require('./utils');

module.exports = class Install {
  /*
  interface Step {
    get name : String
    get failureStep : String
    get view : HTMLElement?
    start(data : *, err : Error, install : Install) : Promise
  }
  */
  constructor(steps, state = {}, options = {}) {
    this.emitter = new Emitter();
    this.flow = new Flow(steps, options);
    this.state = state;
  }

  getTitle() {
    return 'Kite Install';
  }

  // Atom is using `on` unless these methods exists, so to avoid any issue
  // we have them defined here.
  onDidChangeTitle() {}
  onDidChangeModified() {}

  on(event, listener) {
    this.emitter.on(event, listener);
  }

  observeState(listener) {
    listener && listener(this.state);
    return this.onDidUdpdateState(listener);
  }

  onDidUdpdateState(listener) {
    return this.emitter.on('did-update-state', listener);
  }

  onDidChangeCurrentStep(listener) {
    return this.flow.onDidChangeCurrentStep(listener);
  }

  start() {
    return this.flow.start(this.state, this);
  }

  emit(event, data) {
    this.emitter.emit(event, data);
  }


  getCurrentStepView() {
    const step = this.getCurrentStep();
    return step && step.getView();
  }

  getCurrentStep() {
    return this.flow.getCurrentStep();
  }

  updateState(o) {
    this.state = deepMerge(this.state, o);
    this.emitter.emit('did-update-state', this.state);
    // console.log('new state', JSON.stringify(this.state, null, 2));
  }
};

@@ -880,24 +880,109 @@
 ener);%0A  %7D%0A%0A
+  onDidDestroy(listener) %7B%0A    return this.emitter.on('did-destroy', listener);%0A  %7D%0A%0A
   onDidUdpda
@@ -1287,16 +1287,65 @@
 );%0A  %7D%0A%0A
+  destroy() %7B%0A    this.emit('did-destroy');%0A  %7D%0A%0A
 %0A  getCu

Add a destroy method on install