<commit_before>define (require) ->
  
  ng = require 'angular'
  L = require 'lodash'
  ga = require 'analytics'
  require 'services'
  ChooseDialogueCtrl = require './choose-dialogue'
  
  # Run-time requirements
  injectables = L.pairs
    scope: '$scope'
    route: '$route'
    http: '$http'
    location: '$location',
    params: '$routeParams'
    to: '$timeout'
    console: '$log'
    Q: '$q'
    $modal: '$modal'
    connectTo: 'connectTo'
    meetRequest: 'meetRequest'
    Histories: 'Histories'
    Mines: 'Mines'
    silentLocation: '$ngSilentLocation'
    serviceStamp: 'serviceStamp'
    notify: 'notify'

  #--- Functions.

  # Test to see if two strings overlap.
  overlaps = (x, y) -> x && y && (x.indexOf(y) >= 0 || y.indexOf(x) >= 0)

  # Get the configured service at the given URL.
  atURL = (url) -> (mines) -> L.find mines, (m) -> overlaps m.root, url

  # Turn a configuration object into a tool.
  # Currently just adds a handles() method.
  toTool = (conf) ->
    handles = conf.handles
    providers = conf.provides

    if Array.isArray handles
      conf.handles = (cat) -> handles.indexOf(cat) >= 0
    else
      conf.handles = (cat) -> handles is cat

    if Array.isArray providers
      conf.provides = (x) -> x in providers
    else
      conf.provides = (x) -> x is providers
    
    conf

  Controllers = ng.module 'steps.history.controllers', ['steps.services']
  
  Controllers.controller 'HistoryCtrl', class HistoryController

    currentCardinal: 0

    @$inject: (snd for [fst, snd] in injectables)

    constructor: (injected...) ->
      for [name, _], idx in injectables
        @[name] = injected[idx]

      @init()
      @startWatching()

    elide: true

    startWatching: ->
      scope = @scope

      scope.$watchCollection 'items', ->
        exporters = []
        for tool in scope.nextTools when tool.handles 'items'
          for key, data of scope.items when data.ids.length
            exporters.push {key, data, tool}
        otherSteps = (s for s in scope.nextSteps when not s.tool.handles 'items')
        scope.nextSteps = otherSteps.concat(exporters)

      scope.$watch 'messages', (msgs) ->
        handlers = L.values msgs
        otherSteps = (s for s in scope.nextSteps when s.kind isnt 'msg')
        scope.nextSteps = otherSteps.concat(handlers)

      scope.$watch 'list', ->
        listHandlers = []
        for tool in scope.nextTools when tool.handles 'list'
          listHandlers.push {tool, data: scope.list}
        otherSteps = (s for s in scope.nextSteps when not s.tool.handles 'list')
        scope.nextSteps = otherSteps.concat(listHandlers)<commit_msg>Clean up constructor with a decorator<commit_after>define (require) ->
  
  ng = require 'angular'
  L = require 'lodash'
  ga = require 'analytics'
  require 'services'
  ChooseDialogueCtrl = require './choose-dialogue'
  
  # Run-time requirements
  injectables = L.pairs
    scope: '$scope'
    route: '$route'
    http: '$http'
    location: '$location',
    params: '$routeParams'
    to: '$timeout'
    console: '$log'
    Q: '$q'
    $modal: '$modal'
    connectTo: 'connectTo'
    meetRequest: 'meetRequest'
    Histories: 'Histories'
    Mines: 'Mines'
    silentLocation: '$ngSilentLocation'
    serviceStamp: 'serviceStamp'
    notify: 'notify'

  # Test to see if two strings overlap.
  overlaps = (x, y) -> x && y && (x.indexOf(y) >= 0 || y.indexOf(x) >= 0)

  # Get the configured service at the given URL.
  atURL = (url) -> (mines) -> L.find mines, (m) -> overlaps m.root, url

  # Turn a configuration object into a tool.
  # Currently just adds a handles() method.
  toTool = (conf) ->
    handles = conf.handles
    providers = conf.provides

    if Array.isArray handles
      conf.handles = (cat) -> handles.indexOf(cat) >= 0
    else
      conf.handles = (cat) -> handles is cat

    if Array.isArray providers
      conf.provides = (x) -> x in providers
    else
      conf.provides = (x) -> x is providers
    
    conf

  # Decorator to create injecting constructor.
  inject = (fn) -> (injected...) ->
    for [name, _], idx in injectables
      @[name] = injected[idx]
    fn.call @

  Controllers = ng.module 'steps.history.controllers', ['steps.services']
  
  Controllers.controller 'HistoryCtrl', class HistoryController

    currentCardinal: 0

    @$inject: (snd for [fst, snd] in injectables)

    constructor: inject ->
      @init()
      @startWatching()
      console.log @

    elide: true

    startWatching: ->
      scope = @scope

      scope.$watchCollection 'items', ->
        exporters = []
        for tool in scope.nextTools when tool.handles 'items'
          for key, data of scope.items when data.ids.length
            exporters.push {key, data, tool}
        otherSteps = (s for s in scope.nextSteps when not s.tool.handles 'items')
        scope.nextSteps = otherSteps.concat(exporters)

      scope.$watch 'messages', (msgs) ->
        handlers = L.values msgs
        otherSteps = (s for s in scope.nextSteps when s.kind isnt 'msg')
        scope.nextSteps = otherSteps.concat(handlers)

      scope.$watch 'list', ->
        listHandlers = []
        for tool in scope.nextTools when tool.handles 'list'
          listHandlers.push {tool, data: scope.list}
        otherSteps = (s for s in scope.nextSteps when not s.tool.handles 'list')
        scope.nextSteps = otherSteps.concat(listHandlers)
{'fraction_non_alphanumeric': 0.12418906394810009, 'fraction_numerical': 0.0014828544949026877, 'mean_word_length': 2.55467720685112, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '3089461', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1696, 'n_words': 499}