<commit_before>import { assign } from '@ember/polyfills';
import { Promise } from 'rsvp';
import { run } from '@ember/runloop';
import Evented from '@ember/object/evented';
import Service from '@ember/service';
import { debug } from '../utils';
import {
  namespace,
  tabId,
  tabIdKey,
  shouldInvalidateMasterTabKey
} from '../consts';

/** 
 * Checks whether the current tab is the master tab.
 */
function isMasterTab() {
  return localStorage[tabIdKey] === tabId;
}

/** The service factory. */
export default Service.extend(Evented, {
  /** Contains current lock names that will be deleted during the 'beforeunload' window event. */
  lockNames: [],
  resolve: null,
  contestTimeout: null,
  /**
   * Sets up listeners on the 'storage' and 'beforeunload' window events.
   * Returns a promise that resolves immediately if this or another tab is the master tab and that
   * tab is currently present. In case the master tab crashed and a new tab is opened, this promise
   * will resolve after a short delay while it invalidates the master tab.
   */
  setup() {
    const storageHandler = e => {
      switch (e.key) {
        case tabIdKey:
          const newTabId = e.newValue;
          if (newTabId === null) {

            debug('Master tab currently being contested.');
            localStorage[shouldInvalidateMasterTabKey] = false;
            this.registerAsMasterTab();
          } else {
            if (this.get('isMasterTab') && e.oldValue !== null && tabId !== newTabId) {
              debug('Lost master tab status. Probably race condition related.');
              run(() => {
                this.set('isMasterTab', false);
                this.trigger('isMasterTab', false);
              });
            }
          }
          break;
        case shouldInvalidateMasterTabKey:
          const shouldInvalidateMasterTab = eval(e.newValue);<commit_msg>master-tab-factory: Fix default properties linting error<commit_after>import { assign } from '@ember/polyfills';
import { A } from '@ember/array';
import { Promise } from 'rsvp';
import { run } from '@ember/runloop';
import Evented from '@ember/object/evented';
import Service from '@ember/service';
import { debug } from '../utils';
import {
  namespace,
  tabId,
  tabIdKey,
  shouldInvalidateMasterTabKey
} from '../consts';

/**
 * Checks whether the current tab is the master tab.
 */
function isMasterTab() {
  return localStorage[tabIdKey] === tabId;
}

/** The service factory. */
export default Service.extend(Evented, {
  /** Contains current lock names that will be deleted during the 'beforeunload' window event. */
  lockNames: A(),
  resolve: null,
  contestTimeout: null,
  /**
   * Sets up listeners on the 'storage' and 'beforeunload' window events.
   * Returns a promise that resolves immediately if this or another tab is the master tab and that
   * tab is currently present. In case the master tab crashed and a new tab is opened, this promise
   * will resolve after a short delay while it invalidates the master tab.
   */
  setup() {
    const storageHandler = e => {
      switch (e.key) {
        case tabIdKey:
          const newTabId = e.newValue;
          if (newTabId === null) {

            debug('Master tab currently being contested.');
            localStorage[shouldInvalidateMasterTabKey] = false;
            this.registerAsMasterTab();
          } else {
            if (this.get('isMasterTab') && e.oldValue !== null && tabId !== newTabId) {
              debug('Lost master tab status. Probably race condition related.');
              run(() => {
                this.set('isMasterTab', false);
                this.trigger('isMasterTab', false);
              });
            }
          }
          break;
        case shouldInvalidateMasterTabKey:
          const shouldInvalidateMasterTab = eval(e.newValue);
{'fraction_non_alphanumeric': 0.11050299713317696, 'fraction_numerical': 0.0, 'mean_word_length': 2.620754716981132, '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': '3294064', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1024, 'n_words': 357}