 
     beforeEach ->
       Transmitter.startTransmission (tr) =>
-        @createBackwardChannel().init(tr)
+        @createFlatChannel().init(tr)
         @createNestedChannel().init(tr)
 
 


describe 'Flattening connection', ->

  class NestedChannel extends Transmitter.Channels.CompositeChannel

    constructor: (@nestedObject, @serializedVar) ->
      @valueVarDynamic = [@nestedObject?.valueVar].filter (v) -> v?

    @defineChannel ->
      new Transmitter.Channels.SimpleChannel()
        .inForwardDirection()
        .fromDynamicSources @valueVarDynamic
        .toTarget @serializedVar
        .withTransform (valuePayloads) =>
          valuePayloads.merge().map ([value]) =>
            {name: @nestedObject?.name ? null, value: value ? null}


    @defineChannel ->
      new Transmitter.Channels.SimpleChannel()
        .inBackwardDirection()
        .fromSource @serializedVar
        .toDynamicTargets @valueVarDynamic
        .withTransform (serializedPayload) ->
          [serializedPayload.map (serialized) -> serialized?.value]


  beforeEach ->
    @define 'serializedVar', new Transmitter.Nodes.Variable()
    @define 'nestedVar', new Transmitter.Nodes.Variable()
    @define 'nestedChannelVar', new Transmitter.ChannelNodes.ChannelVariable()

    @createBackwardChannel = =>
      new Transmitter.Channels.SimpleChannel()
        .inBackwardDirection()
        .fromSource @serializedVar
        .toTarget @nestedVar
        .withTransform (payload) ->
          payload.map (serialized) ->
            if serialized?
              return new NestedObject(serialized.name)
            else
              null

    @createNestedChannel = =>
      new Transmitter.Channels.SimpleChannel()
        .fromSource @nestedVar
        .toConnectionTarget @nestedChannelVar
        .withTransform (payload) =>
          payload.map (nestedObject) =>
            new NestedChannel(nestedObject, @serializedVar)


  describe 'initialization', ->

    specify 'has default const value after initialization', ->
      Transmitter.startTransmission (tr) =>
        @createBackwardChannel().init(tr)

      # Separate transmissions to test channel init querying
      Transmitter.startTransmission (tr) =>


        Transmitter.startTransmission (tr) =>
          tr.reverseOrder = order is 'reverse'
          @createFlatChannel().init(tr)
          @createNestedChannel().init(tr)
          @createDerivedChannel().init(tr)

