<commit_before>/**
 * Copyright (c) 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @providesModule RelayModernEnvironment
 * @flow
 * @format
 */

'use strict';

const RelayCore = require('RelayCore');
const RelayDataLoader = require('RelayDataLoader');
const RelayDefaultHandlerProvider = require('RelayDefaultHandlerProvider');
const RelayInMemoryRecordSource = require('RelayInMemoryRecordSource');
const RelayPublishQueue = require('RelayPublishQueue');

const isPromise = require('isPromise');
const normalizePayload = require('normalizePayload');
const normalizeRelayPayload = require('normalizeRelayPayload');
const warning = require('warning');

import type {CacheConfig, Disposable} from 'RelayCombinedEnvironmentTypes';
import type {EnvironmentDebugger} from 'RelayDebugger';
import type {HandlerProvider} from 'RelayDefaultHandlerProvider';
import type {
  Network,
  PayloadData,
  PayloadError,
  RelayResponsePayload,
  UploadableMap,
} from 'RelayNetworkTypes';
import type RelayObservable from 'RelayObservable';
import type {
  Environment,
  MissingFieldHandler,
  OperationSelector,
  OptimisticUpdate,
  Selector,
  SelectorStoreUpdater,
  Snapshot,
  Store,
  StoreUpdater,
  UnstableEnvironmentCore,
} from 'RelayStoreTypes';

export type EnvironmentConfig = {
  configName?: string,
  handlerProvider?: HandlerProvider,
  network: Network,
  store: Store,
};

class RelayModernEnvironment implements Environment {
  _network: Network;
  _publishQueue: RelayPublishQueue;
  _store: Store;
  _debugger: ?EnvironmentDebugger;
  configName: ?string;
  unstable_internal: UnstableEnvironmentCore;

  constructor(config: EnvironmentConfig) {
    this.configName = config.configName;
    const handlerProvider = config.handlerProvider
      ? config.handlerProvider
      : RelayDefaultHandlerProvider;
    this._network = config.network;
    this._publishQueue = new RelayPublishQueue(config.store, handlerProvider);
    this._store = config.store;
    this.unstable_internal = RelayCore;

    (this: any).__setNet = newNet => (this._network = newNet);

    if (__DEV__) {
      const g = typeof global !== 'undefined' ? global : window;

      // Attach the debugger symbol to the global symbol so it can be accessed by
      // devtools extension.
      if (!g.__RELAY_DEBUGGER__) {
        const {RelayDebugger} = require('RelayDebugger');
        g.__RELAY_DEBUGGER__ = new RelayDebugger();

        // Setup the runtime part for Native
        if (typeof g.registerDevtoolsPlugin === 'function') {
          g.registerDevtoolsPlugin(
            require('relay-debugger-react-native-runtime'),
          );
        }
      }

      const envId = g.__RELAY_DEBUGGER__.registerEnvironment(this);
      this._debugger = g.__RELAY_DEBUGGER__.getEnvironmentDebugger(envId);
    } else {
      this._debugger = null;
    }
  }

  getStore(): Store {
    return this._store;
  }

  getDebugger(): ?EnvironmentDebugger {
    return this._debugger;
  }

  applyUpdate(optimisticUpdate: OptimisticUpdate): Disposable {
    const dispose = () => {
      this._publishQueue.revertUpdate(optimisticUpdate);
      this._publishQueue.run();
    };
    this._publishQueue.applyUpdate(optimisticUpdate);
    this._publishQueue.run();
    return {dispose};
  }
<commit_msg>Disable RN devtools plugin for Relay<commit_after>/**
 * Copyright (c) 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @providesModule RelayModernEnvironment
 * @flow
 * @format
 */

'use strict';

const RelayCore = require('RelayCore');
const RelayDataLoader = require('RelayDataLoader');
const RelayDefaultHandlerProvider = require('RelayDefaultHandlerProvider');
const RelayInMemoryRecordSource = require('RelayInMemoryRecordSource');
const RelayPublishQueue = require('RelayPublishQueue');

const isPromise = require('isPromise');
const normalizePayload = require('normalizePayload');
const normalizeRelayPayload = require('normalizeRelayPayload');
const warning = require('warning');

import type {CacheConfig, Disposable} from 'RelayCombinedEnvironmentTypes';
import type {EnvironmentDebugger} from 'RelayDebugger';
import type {HandlerProvider} from 'RelayDefaultHandlerProvider';
import type {
  Network,
  PayloadData,
  PayloadError,
  RelayResponsePayload,
  UploadableMap,
} from 'RelayNetworkTypes';
import type RelayObservable from 'RelayObservable';
import type {
  Environment,
  MissingFieldHandler,
  OperationSelector,
  OptimisticUpdate,
  Selector,
  SelectorStoreUpdater,
  Snapshot,
  Store,
  StoreUpdater,
  UnstableEnvironmentCore,
} from 'RelayStoreTypes';

export type EnvironmentConfig = {
  configName?: string,
  handlerProvider?: HandlerProvider,
  network: Network,
  store: Store,
};

class RelayModernEnvironment implements Environment {
  _network: Network;
  _publishQueue: RelayPublishQueue;
  _store: Store;
  _debugger: ?EnvironmentDebugger;
  configName: ?string;
  unstable_internal: UnstableEnvironmentCore;

  constructor(config: EnvironmentConfig) {
    this.configName = config.configName;
    const handlerProvider = config.handlerProvider
      ? config.handlerProvider
      : RelayDefaultHandlerProvider;
    this._network = config.network;
    this._publishQueue = new RelayPublishQueue(config.store, handlerProvider);
    this._store = config.store;
    this.unstable_internal = RelayCore;

    (this: any).__setNet = newNet => (this._network = newNet);

    if (__DEV__) {
      const g = typeof global !== 'undefined' ? global : window;

      // Attach the debugger symbol to the global symbol so it can be accessed by
      // devtools extension.
      if (!g.__RELAY_DEBUGGER__) {
        const {RelayDebugger} = require('RelayDebugger');
        g.__RELAY_DEBUGGER__ = new RelayDebugger();
      }

      const envId = g.__RELAY_DEBUGGER__.registerEnvironment(this);
      this._debugger = g.__RELAY_DEBUGGER__.getEnvironmentDebugger(envId);
    } else {
      this._debugger = null;
    }
  }

  getStore(): Store {
    return this._store;
  }

  getDebugger(): ?EnvironmentDebugger {
    return this._debugger;
  }

  applyUpdate(optimisticUpdate: OptimisticUpdate): Disposable {
    const dispose = () => {
      this._publishQueue.revertUpdate(optimisticUpdate);
      this._publishQueue.run();
    };
    this._publishQueue.applyUpdate(optimisticUpdate);
    this._publishQueue.run();
    return {dispose};
  }

{'fraction_non_alphanumeric': 0.09523112931538912, 'fraction_numerical': 0.0011702750146284377, 'mean_word_length': 4.34140625, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823092', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1909, 'n_words': 489}