<commit_before>noflo = require 'noflo'

class ConnectRuntime extends noflo.Component
  constructor: ->
    @editor = null
    @runtime = null
    @inPorts =
      editor: new noflo.Port 'object'
      runtime: new noflo.Port 'object'
    @outPorts = {}

    @inPorts.editor.on 'data', (@editor) =>
      @connect @editor, @runtime
    @inPorts.runtime.on 'data', (@runtime) =>
      @connect @editor, @runtime

  connect: (editor, runtime) ->
    return unless editor and runtime
    for name, plugin of editor.plugins
      continue unless plugin.registerRuntime
      plugin.registerRuntime runtime

    runtime.once 'connected', ->
      # TODO: Read basedir from graph?
      runtime.sendComponent 'list', 'noflo-ui-preview'
    runtime.on 'connected', =>
      runtime.sendGraph 'clear',
        baseDir: 'noflo-ui-preview'
      graph = editor.toJSON()
      for name, definition of graph.processes
        runtime.sendGraph 'addnode',
          id: name
          component: definition.component
          metadata: definition.metadata
      for edge in graph.connections<commit_msg>Always read components when connected<commit_after>noflo = require 'noflo'

class ConnectRuntime extends noflo.Component
  constructor: ->
    @editor = null
    @runtime = null
    @inPorts =
      editor: new noflo.Port 'object'
      runtime: new noflo.Port 'object'
    @outPorts = {}

    @inPorts.editor.on 'data', (@editor) =>
      @connect @editor, @runtime
    @inPorts.runtime.on 'data', (@runtime) =>
      @connect @editor, @runtime

  connect: (editor, runtime) ->
    return unless editor and runtime
    for name, plugin of editor.plugins
      continue unless plugin.registerRuntime
      plugin.registerRuntime runtime

    runtime.on 'connected', =>
      # TODO: Read basedir from graph?
      runtime.sendComponent 'list', 'noflo-ui-preview'
      runtime.sendGraph 'clear',
        baseDir: 'noflo-ui-preview'
      graph = editor.toJSON()
      for name, definition of graph.processes
        runtime.sendGraph 'addnode',
          id: name
          component: definition.component
          metadata: definition.metadata
      for edge in graph.connections
{'fraction_non_alphanumeric': 0.1040994933210502, 'fraction_numerical': 0.0, 'mean_word_length': 2.731958762886598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '499685', 'n_tokens_mistral': 621, 'n_tokens_neox': 605, 'n_words': 175}