<commit_before>import Ember from 'ember';

const { inject: { service } } = Ember;

export default Ember.Service.extend(Ember.Evented, {
  windowMessengerEvents: service(),

  init() {
    this._super(...arguments);
    this.get('windowMessengerEvents').on('from:ember-window-messenger-client', this, this._onMessage);
  },

  /**
   * Send response to back to client
   *
   * @param  {String}  uuid
   * @param  {Object}  payload
   * @param  {MessageEvent}  event
   * @param  {Boolean} hasError
   */
  _respond(uuid, payload, event, hasError) {
    let query = {
      id: uuid,
      type: 'ember-window-messenger-server',
      response: payload,
      error: hasError
    };
    event.source.postMessage(JSON.stringify(query), event.origin);
  },

  /**
   * Handle message that we got from Messenger Events
   *
   * @param  {Object} message
   */
  _onMessage(message) {
    this.trigger(message.name, (response) => {
      this._respond(message.id, response, event, false);
    }, (response) => {
      this._respond(message.id, response, event, true);
    }, message.query);
  },

  willDestroy() {
    this._super(...arguments);
    this.get('windowMessengerEvents').off('from:ember-window-messenger-client', this, this._onMessage);
  }
});
<commit_msg>don't use event global variable as it is not supported by FF<commit_after>import Ember from 'ember';

const { inject: { service } } = Ember;

export default Ember.Service.extend(Ember.Evented, {
  windowMessengerEvents: service(),

  init() {
    this._super(...arguments);
    this.get('windowMessengerEvents').on('from:ember-window-messenger-client', this, this._onMessage);
  },

  /**
   * Send response to back to client
   *
   * @param  {String}  uuid
   * @param  {Object}  payload
   * @param  {MessageEvent}  event
   * @param  {Boolean} hasError
   */
  _respond(uuid, payload, event, hasError) {
    let query = {
      id: uuid,
      type: 'ember-window-messenger-server',
      response: payload,
      error: hasError
    };
    event.source.postMessage(JSON.stringify(query), event.origin);
  },

  /**
   * Handle message that we got from Messenger Events
   *
   * @param  {Object} message
   * @param  {Object} event
   */
  _onMessage(message, event) {
    this.trigger(message.name, (response) => {
      this._respond(message.id, response, event, false);
    }, (response) => {
      this._respond(message.id, response, event, true);
    }, message.query);
  },

  willDestroy() {
    this._super(...arguments);
    this.get('windowMessengerEvents').off('from:ember-window-messenger-client', this, this._onMessage);
  }
});

{'fraction_non_alphanumeric': 0.15160796324655437, 'fraction_numerical': 0.0, 'mean_word_length': 3.1542130365659777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3273136', 'n_tokens_mistral': 851, 'n_tokens_neox': 828, 'n_words': 177}