<commit_before>var card = Conductor.card({
  consumers: {
    cardManager: Conductor.Oasis.Consumer.extend({
      events: {
        addCard: function(newCard) {
          var cardInstance = this.card;
          var cardLength = cardInstance.data.cards.length;
          cardInstance.addCard(newCard);
          cardInstance.prepareSlot(newCard);
          cardInstance.appendCard(newCard, cardLength);
        },

        destroyCard: function(uuid) {
          this.card.destroyCards();
          // this.card.destroyCard(uuid);
        }
      }
    })
  },

  services: {
    cardManager: Conductor.Oasis.Service.extend({
      initialize: function (port) {
        this.sandbox.cardManagerPort = port;
      },

      destroyCard: function() {
        this.send('destroyCard');
      }
    })
  },

  render: function(slotId) {
    this.slotId = slotId;
    this.prepareSlots();
    this.bootCards();
  },

  prepareSlots: function prepareSlots() {
    this.data.cards.forEach(this.prepareSlot, this);
  },

  prepareSlot: function(card) {
    var slot = document.querySelector(this.slotId);
    var element = document.createElement('div');
    var uuid = card.uuid || UUID.generate();

    element.id = slot.id + '-' + uuid;
    card.elementId = '#' + element.id;

    slot.appendChild(element);
  },

  bootCards: function bootCards() {
    var cardContainer = this;
    var cards = this.data.cards;

    cardContainer.conductor = new Conductor();

    cards.forEach(cardContainer.appendCard, this);
  },

  addCard: function(card) {
    var cards = this.data.cards;
    cards.push(card);
    return card;
  },

  appendCard: function(card, index) {
    var conductorInstance = this.conductor;
    var slotId = this.slotId;
    var el = card.elementId;
    var uuid = card.uuid;
    var adapter = card.options.adapter;

    var cardAdapter = Conductor.adapters[adapter];

    conductorInstance.addDefaultCapability('cardManager', this.services.cardManager);

    var cardInstance = conductorInstance.load(card.url, index, {
      adapter: cardAdapter
    });

    if (adapter === 'iframe') {
      cardInstance.appendTo(el);
    } else {
      cardInstance.render(el);
    }

    card.instance = cardInstance;
  },

  destroyCards: function() {
    this.data.cards.forEach(this.destroyCard, this);
  },

  destroyCard: function(card) {
    var conductorInstance = this.conductor;
    var instance = card.instance;
    var element = document.querySelector(card.elementId);

    instance.waitForLoad().then(function(loadedInstance) {
      loadedInstance.sandbox.capabilities.cardManager.destroyCard();
      element.remove();
    });
  }
});<commit_msg>Destroy the card instance in `destroyCard`.<commit_after>var card = Conductor.card({
  consumers: {
    cardManager: Conductor.Oasis.Consumer.extend({
      events: {
        addCard: function(newCard) {
          var cardInstance = this.card;
          var cardLength = cardInstance.data.cards.length;
          cardInstance.addCard(newCard);
          cardInstance.prepareSlot(newCard);
          cardInstance.appendCard(newCard, cardLength);
        },

        destroyCard: function(uuid) {
          this.card.destroyCards();
          // this.card.destroyCard(uuid);
        }
      }
    })
  },

  services: {
    cardManager: Conductor.Oasis.Service.extend({
      initialize: function (port) {
        this.sandbox.cardManagerPort = port;
      },

      destroyCard: function() {
        this.send('destroyCard');
      }
    })
  },

  render: function(slotId) {
    this.slotId = slotId;
    this.prepareSlots();
    this.bootCards();
  },

  prepareSlots: function prepareSlots() {
    this.data.cards.forEach(this.prepareSlot, this);
  },

  prepareSlot: function(card) {
    var slot = document.querySelector(this.slotId);
    var element = document.createElement('div');
    var uuid = card.uuid || UUID.generate();

    element.id = slot.id + '-' + uuid;
    card.elementId = '#' + element.id;

    slot.appendChild(element);
  },

  bootCards: function bootCards() {
    var cardContainer = this;
    var cards = this.data.cards;

    cardContainer.conductor = new Conductor();

    cards.forEach(cardContainer.appendCard, this);
  },

  addCard: function(card) {
    var cards = this.data.cards;
    cards.push(card);
    return card;
  },

  appendCard: function(card, index) {
    var conductorInstance = this.conductor;
    var slotId = this.slotId;
    var el = card.elementId;
    var uuid = card.uuid;
    var adapter = card.options.adapter;

    var cardAdapter = Conductor.adapters[adapter];

    conductorInstance.addDefaultCapability('cardManager', this.services.cardManager);

    var cardInstance = conductorInstance.load(card.url, index, {
      adapter: cardAdapter
    });

    if (adapter === 'iframe') {
      cardInstance.appendTo(el);
    } else {
      cardInstance.render(el);
    }

    card.instance = cardInstance;
  },

  destroyCards: function() {
    this.data.cards.forEach(this.destroyCard, this);
  },

  destroyCard: function(card) {
    var conductorInstance = this.conductor;
    var instance = card.instance;
    var element = document.querySelector(card.elementId);

    instance.waitForLoad().then(function(loadedInstance) {
      loadedInstance.sandbox.capabilities.cardManager.destroyCard();
      return { element: element, loadedInstance: loadedInstance };
    })
    .then(function(data) {
      var element = data.element;
      var loadedInstance = data.loadedInstance;

      loadedInstance.destroy();
      element.remove();
    });

  }
});
{'fraction_non_alphanumeric': 0.1275831087151842, 'fraction_numerical': 0.0, 'mean_word_length': 2.8175582990397805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2815803', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1632, 'n_words': 298}