<commit_before>import xs from 'xstream'
import { run } from '@cycle/run'
import { makeDOMDriver } from '@cycle/dom'

import { board as boardController } from 'board'
import { moveHistory as moveHistoryController } from 'move-history'

import { combinedDOM } from 'view'

const localizeReducer = namespace => reducer => state => Object.assign(state, { [namespace]: reducer(state[namespace]) })
const delocalizeState = (namespace, state$) => state$.map(({ [namespace]: subState }) => subState)

const main = (sources) => {
  const board1 = boardController.main1(sources)
  const moveHistory1 = moveHistoryController.main1(board1)

  const reducer$ = xs.merge(
    board1.reducer$.map(localizeReducer('board')),
    moveHistory1.reducer$.map(localizeReducer('moveHistory'))
  )
  const state$ = reducer$.fold((board, reducer) => reducer(board), {
    board: board1.initialState,
    moveHistory: moveHistory1.initialState
  })

  const board$ = delocalizeState('board', state$)
  const moveHistory$ = delocalizeState('moveHistory', state$)

  const board2 = boardController.main2({ board$ })
  const moveHistory2 = moveHistoryController.main2({ moveHistory$ })

  const combinedDOM$ = xs.combine(board2.DOM, moveHistory2.DOM)
    .map(combinedDOM).remember()

  return {
    DOM: combinedDOM$
  }
}

const drivers = {
  DOM: makeDOMDriver('#free-the-clones'),
}

run(main, drivers)
<commit_msg>lift state from main analogously to lifting state from board and moveHistory<commit_after>import xs from 'xstream'
import { run } from '@cycle/run'
import { makeDOMDriver } from '@cycle/dom'

import { board as boardController } from 'board'
import { moveHistory as moveHistoryController } from 'move-history'

import { combinedDOM } from 'view'

const localizeReducer = namespace => reducer => state => Object.assign(state, { [namespace]: reducer(state[namespace]) })
const delocalizeState = (namespace, state$) => state$.map(({ [namespace]: subState }) => subState)

const main1 = (sources) => {
  const board1 = boardController.main1(sources)
  const moveHistory1 = moveHistoryController.main1(board1)

  const reducer$ = xs.merge(
    board1.reducer$.map(localizeReducer('board')),
    moveHistory1.reducer$.map(localizeReducer('moveHistory'))
  )

  const initialState = {
    board: board1.initialState,
    moveHistory: moveHistory1.initialState
  }

  return {
    reducer$,
    initialState
  }
}

const main2 = ({ state$ }) => {
  const board$ = delocalizeState('board', state$)
  const moveHistory$ = delocalizeState('moveHistory', state$)

  const board2 = boardController.main2({ board$ })
  const moveHistory2 = moveHistoryController.main2({ moveHistory$ })

  const combinedDOM$ = xs.combine(board2.DOM, moveHistory2.DOM)
    .map(combinedDOM).remember()

  return {
    DOM: combinedDOM$
  }
}

const main = (sources) => {
  const { reducer$, initialState } = main1(sources)
  const state$ = reducer$.fold((board, reducer) => reducer(board), initialState)
  return main2({ state$ })
}

const drivers = {
  DOM: makeDOMDriver('#free-the-clones'),
}

run(main, drivers)

{'fraction_non_alphanumeric': 0.13662979830839297, 'fraction_numerical': 0.011060507482108002, 'mean_word_length': 4.857142857142857, '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': '3544305', 'n_tokens_mistral': 969, 'n_tokens_neox': 942, 'n_words': 224}