<commit_before>kd                      = require 'kd'
async                   = require 'async'
actions                 = require './actiontypes'
getters                 = require './getters'
Promise                 = require 'bluebird'
Machine                 = require 'app/providers/machine'
remote                  = require('app/remote').getInstance()
Promise                 = require 'bluebird'
showError               = require 'app/util/showError'
toImmutable             = require 'app/util/toImmutable'
environmentDataProvider = require 'app/userenvironmentdataprovider'


_eventsCache =
  machine    : {}
  stack      : no


_bindMachineEvents = (environmentData) ->

  { reactor, computeController } = kd.singletons

  machines = reactor.evaluate getters.machinesWithWorkspaces

  machines.map (machine, id) ->

    return  if _eventsCache.machine[id]

    _eventsCache.machine[id] = yes

    computeController.on "public-#{id}", (event) ->

      reactor.dispatch actions.MACHINE_UPDATED, { id, event }

    computeController.on "revive-#{id}", (newMachine) ->

      return loadMachines()  unless newMachine

      reactor.dispatch actions.MACHINE_UPDATED, { id, machine: newMachine }


  # TODO: when a machine shared/collaborate, SharedMachineInvitation and
  # CollaborationInvitation event listeners trigger two times.
  # szkl can you check it why trigger these events two times?
  # When we fix it this problem, gokhansongul will create a new pr for deleting
  # forceUpdate parameter from ActiveInvitationMachineIdStore setMachineId event handler

  kd.singletons.notificationController
    .on 'SharedMachineInvitation', handleSharedMachineInvitation
    .on 'CollaborationInvitation', handleSharedMachineInvitation


_bindStackEvents = ->

  return  if _eventsCache.stack is yes

  _eventsCache.stack = yes

  { reactor, computeController } = kd.singletons

  computeController.ready ->
    computeController.on 'StackRevisionChecked', (stack) ->
      return  if _revisionStatus?.error? and not stack._revisionStatus.status
<commit_msg>Environment: Actions: Show progress bars while the stack resources are building<commit_after>kd                      = require 'kd'
async                   = require 'async'
actions                 = require './actiontypes'
getters                 = require './getters'
Promise                 = require 'bluebird'
Machine                 = require 'app/providers/machine'
remote                  = require('app/remote').getInstance()
Promise                 = require 'bluebird'
showError               = require 'app/util/showError'
toImmutable             = require 'app/util/toImmutable'
environmentDataProvider = require 'app/userenvironmentdataprovider'


_eventsCache =
  machine    : {}
  stack      : no


_bindMachineEvents = (environmentData) ->

  { reactor, computeController } = kd.singletons

  machines = reactor.evaluate getters.machinesWithWorkspaces

  computeController.ready ->

    machines.map (machine, id) ->
      return  if _eventsCache.machine[id]

      _eventsCache.machine[id] = yes

      computeController.on "public-#{id}", (event) ->
        reactor.dispatch actions.MACHINE_UPDATED, { id, event }

      computeController.on "revive-#{id}", (newMachine) ->
        return loadMachines()  unless newMachine
        reactor.dispatch actions.MACHINE_UPDATED, { id, machine: newMachine }

      if stack = computeController.findStackFromMachineId id
        computeController.on "apply-#{stack._id}", (event) ->
          reactor.dispatch actions.MACHINE_UPDATED, { id, event }

        if stack.status?.state is Machine.State.Building
          computeController.eventListener.addListener 'apply', stack._id


  # TODO: when a machine shared/collaborate, SharedMachineInvitation and
  # CollaborationInvitation event listeners trigger two times.
  # szkl can you check it why trigger these events two times?
  # When we fix it this problem, gokhansongul will create a new pr for deleting
  # forceUpdate parameter from ActiveInvitationMachineIdStore setMachineId event handler

  kd.singletons.notificationController
    .on 'SharedMachineInvitation', handleSharedMachineInvitation
    .on 'CollaborationInvitation', handleSharedMachineInvitation


_bindStackEvents = ->

  return  if _eventsCache.stack is yes

  _eventsCache.stack = yes

  { reactor, computeController } = kd.singletons

  computeController.ready ->
    computeController.on 'StackRevisionChecked', (stack) ->
      return  if _revisionStatus?.error? and not stack._revisionStatus.status

{'fraction_non_alphanumeric': 0.08327840035157108, 'fraction_numerical': 0.0, 'mean_word_length': 3.007042253521127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4221033', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1181, 'n_words': 317}