<commit_before>import invariant from 'invariant'
const mechanism = 'socketsync'

/**
 * Creates a web sockets synchronizer to synchronize events between tabs.
 * @param  {string}   key                       The key to synchronize on.
 * @param  {function} action                    The action to run when trigger is executed. Should return the payload to be transmitted to the handlers on other tabs.
 * @param  {function} handler                   The handler which is executed on other tabs when a synchronization is triggered. Argument is the return value of the action.
 * @param  {boolean}  [options.tracing=false]   Option to turn on tracing for debugging.
 * @param  {Object}   [options.logger=console]  The logger to debug to.
 * @param  {string}   [options.logLevel=info]   The log level to trace at.
 * @return {Object}                             socketsync instance with start, stop, trigger, isRunning, and isFallback mock properties.
 */
export default function socketsync(key, action, handler, { tracing = false, logger = console, logLevel = 'info' } = {}) {
  invariant(key)
  invariant(action)
  invariant(handler)
  const log = (...args) => tracing ? logger[logLevel](...args) : () => {}
  let isRunning = false

  const trigger = (...args) => {
    log('socketsync#trigger', args)
    const value = action(...args)
    log('socketsync#trigger action output ignored', args, value)
  }

  const start = () => {
    log('socketsync#start')
    isRunning = true
  }

  const stop = () => {
    log('socketsync#stop')
    isRunning = false
  }

  return  { start
          , stop
          , trigger
          , get isRunning () { return isRunning }
          , mechanism
          , isFallback: false
          , isServer: false
          }<commit_msg>Add invariant messages to socketsync<commit_after>import invariant from 'invariant'
const mechanism = 'socketsync'

/**
 * Creates a web sockets synchronizer to synchronize events between tabs.
 * @param  {string}   key                       The key to synchronize on.
 * @param  {function} action                    The action to run when trigger is executed. Should return the payload to be transmitted to the handlers on other tabs.
 * @param  {function} handler                   The handler which is executed on other tabs when a synchronization is triggered. Argument is the return value of the action.
 * @param  {boolean}  [options.tracing=false]   Option to turn on tracing for debugging.
 * @param  {Object}   [options.logger=console]  The logger to debug to.
 * @param  {string}   [options.logLevel=info]   The log level to trace at.
 * @return {Object}                             socketsync instance with start, stop, trigger, isRunning, and isFallback mock properties.
 */
export default function socketsync(key, action, handler, { tracing = false, logger = console, logLevel = 'info' } = {}) {
  invariant(key, 'key is required')
  invariant(action, 'action is required')
  invariant(handler, 'handler is required')
  const log = (...args) => tracing ? logger[logLevel](...args) : () => {}
  let isRunning = false

  const trigger = (...args) => {
    log('socketsync#trigger', args)
    const value = action(...args)
    log('socketsync#trigger action output ignored', args, value)
  }

  const start = () => {
    log('socketsync#start')
    isRunning = true
  }

  const stop = () => {
    log('socketsync#stop')
    isRunning = false
  }

  return  { start
          , stop
          , trigger
          , get isRunning () { return isRunning }
          , mechanism
          , isFallback: false
          , isServer: false
          }
{'fraction_non_alphanumeric': 0.10466721900027616, 'fraction_numerical': 0.0, 'mean_word_length': 2.600397614314115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6702430', 'n_tokens_mistral': 990, 'n_tokens_neox': 955, 'n_words': 359}