<commit_before>noflo = require 'noflo'

exports.getComponent = ->
  c = new noflo.Component
  c.inPorts.add 'context',
    datatype: 'object'

  c.outPorts.add 'context',
    datatype: 'object'

  noflo.helpers.WirePattern c,
    in: 'context'
    out: 'context'
    forwardGroup: true
  , (context, groups, out) ->
    c.removeListener()
    c.addListener context.runtime, context.graphs?[0]
    out.send context

  c.setRuntimeDebug = (enable) ->
    c.runtime.sendNetwork 'debug',
      graph: c.graph.properties.id or c.graph.name
      enable: enable

  c.addListener = (runtime, graph) ->
    return unless runtime? and graph?
    c.runtime = runtime
    c.graph = graph
    c.listener = (status) =>
      return unless status.online
      c.setRuntimeDebug true
    c.runtime.on 'status', c.listener
    c.setRuntimeDebug true if c.runtime?.isConnected()

  c.removeListener = ->
    return unless c.listener
    return unless c.runtime
    # Disable debug on old runtime
    c.setRuntimeDebug false if c.runtime.isConnected()
    # Stop listening
    c.runtime.removeListener 'status', c.listener<commit_msg>ContextToDebug: handle library name with graphs<commit_after>noflo = require 'noflo'

exports.getComponent = ->
  c = new noflo.Component
  c.inPorts.add 'context',
    datatype: 'object'

  c.outPorts.add 'context',
    datatype: 'object'

  noflo.helpers.WirePattern c,
    in: 'context'
    out: 'context'
    forwardGroup: true
  , (context, groups, out) ->
    c.removeListener()
    c.addListener context.runtime, context.graphs?[0]
    out.send context

  c.setRuntimeDebug = (enable) ->
    c.runtime.sendNetwork 'debug',
      graph: @graphId
      enable: enable

  c.addListener = (runtime, graph) ->
    return unless runtime? and graph?
    @runtime = runtime
    @graph = graph
    @graphId = if graph.properties.library? then "#{graph.properties.library}/#{graph.properties.id}" else graph.properties.id
    @listener = (status) =>
      return unless status.online
      c.setRuntimeDebug true
    @runtime.on 'status', c.listener
    @setRuntimeDebug true if @runtime.isConnected()

  c.removeListener = ->
    return unless @listener and @runtime
    # Disable debug on old runtime
    @setRuntimeDebug false if @runtime.isConnected()
    # Stop listening
    @runtime.removeListener 'status', @listener
{'fraction_non_alphanumeric': 0.11467693624304665, 'fraction_numerical': 0.0008557980316645272, 'mean_word_length': 3.10896309314587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4129554', 'n_tokens_mistral': 737, 'n_tokens_neox': 723, 'n_words': 186}