<commit_before>import $ from 'jquery';
import '../../../lib/select2';
import app from '../../../app';
import loadTemplate from '../../../utils/loadTemplate';
import baseView from '../../baseVw';
import Listing from '../../../models/listing/Listing';
import ShippingOptions from './ShippingOptions';

export default class extends baseView {
  constructor(options = {}) {
    super(options);
    this.options = options;

    if (!this.model || !(this.model instanceof Listing)) {
      throw new Error('Please provide a listing model');
    }

    this.selectedAddress = app.settings.get('shippingAddresses').length ?
      app.settings.get('shippingAddresses').at(0) : '';

    this.listenTo(app.settings.get('shippingAddresses'), 'update', (col) => {
      // if all the addresses were deleted, update with blank values
      if (!col.models.length) {
        this.selectedAddress = '';
        this.trigger('shippingOptionSelected', { name: '', service: '' });
      }
      this.render();
    });

    this.selectedOption = {};
  }

  className() {
    return 'shipping';
  }

  events() {
    return {
      'change #shippingAddress': 'changeShippingAddress',
    };
  }

  get selectedAddress() {
    return this._selectedAddress;
  }

  set selectedAddress(address) {
    this._selectedAddress = address;
  }

  get countryCode() {
    return this.selectedAddress ? this.selectedAddress.get('country') : '';
  }
<commit_msg>handle selected address changing<commit_after>import $ from 'jquery';
import '../../../lib/select2';
import app from '../../../app';
import loadTemplate from '../../../utils/loadTemplate';
import baseView from '../../baseVw';
import Listing from '../../../models/listing/Listing';
import ShippingOptions from './ShippingOptions';

export default class extends baseView {
  constructor(options = {}) {
    super(options);
    this.options = options;

    if (!this.model || !(this.model instanceof Listing)) {
      throw new Error('Please provide a listing model');
    }

    this.selectedAddress = app.settings.get('shippingAddresses').length ?
      app.settings.get('shippingAddresses').at(0) : '';

    this.listenTo(app.settings.get('shippingAddresses'), 'update', (col) => {
      // if all the addresses were deleted, update with blank values
      if (!col.models.length) {
        this.selectedAddress = '';
        this.trigger('shippingOptionSelected', { name: '', service: '' });
      } else {
        // If the old selected address doesn't exist any more, select the first address.
        const userAddresses = app.settings.get('shippingAddresses');
        this.selectedAddress = userAddresses.get(this.selectedAddress) ?
          this.selectedAddress : userAddresses.at(0);
      }
      this.render();
    });

    this.selectedOption = {};
  }

  className() {
    return 'shipping';
  }

  events() {
    return {
      'change #shippingAddress': 'changeShippingAddress',
    };
  }

  get selectedAddress() {
    return this._selectedAddress;
  }

  set selectedAddress(address) {
    this._selectedAddress = address;
  }

  get countryCode() {
    return this.selectedAddress ? this.selectedAddress.get('country') : '';
  }

{'fraction_non_alphanumeric': 0.15801070192005037, 'fraction_numerical': 0.0015738117721120553, 'mean_word_length': 2.992462311557789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4423363', 'n_tokens_mistral': 891, 'n_tokens_neox': 881, 'n_words': 206}