<commit_before>require("../../app.css")
import Rx from 'rx'
const {merge,just} = Rx.Observable
const of = Rx.Observable.of

//views & wrappers
import Settings from '../../components/widgets/Settings'
import FullScreenToggler from '../../components/widgets/FullScreenToggler/index'
import Help from '../../components/widgets/Help'

import {combineLatestObj} from '../../utils/obsUtils'

import {pick, equals} from 'ramda'

import {EntityInfosWrapper,BOMWrapper,GLWrapper,CommentsWrapper,progressBarWrapper} from '../../components/main/wrappers'

import intent from './intent'
import model  from './model'
import view   from './view'


import api from '../../api'

export default function main(sources) {
  const {DOM} = sources

  const actions = intent(sources)
  const state$  = model(undefined, actions, sources)

  //create visual elements
  const entityInfos = EntityInfosWrapper(state$,DOM)
  const comments    = CommentsWrapper(state$,DOM)
  const gl          = GLWrapper(state$, sources)
  const bom         = BOMWrapper(state$,DOM)
  const progressBar = progressBarWrapper(state$,DOM)

  const settingsC   = Settings({DOM, props$:state$})
  const fsToggler   = FullScreenToggler({DOM})
  const help        = Help({DOM, props$:state$})

  //outputs
  const vtree$  = view(state$, settingsC.DOM, fsToggler.DOM, bom.DOM,gl.DOM
    , entityInfos.DOM, comments.DOM, progressBar.DOM, help.DOM)
  const events$ = of( {gl:gl.events, entityInfos:entityInfos.events
    , bom:bom.events, comments:comments.events} )


  function postMsg(api$){
     return api$.map(data=>{
        const {request, response, requestName} = data
        return {target: request.source, message: response, targetOrigin:request.origin, requestName }
      })
  }

  const postMsg$ = postMsg( api( actions,state$ ) )

  //output to localStorage
  //in this case, settings
  const localStorage$ = state$
    .pluck("settings")
    .map( s=>({"jam!-settings":JSON.stringify(s)}) )


  //ym
  //this are responses from ym
  const designExists$ = sources.ym
    //.tap(e=>console.log("responses from ym",e))
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'designExists')
    .flatMap( data => data.catch(_=>just({error:true})) )//flag errors
    .filter(e=>!e.progress)//filter out progress data
    .map(data=> data.error ? false : true)//if we have an error return false, true otherwise
    //.forEach(e=>console.log("designExists: ",e))

  const inBom = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'bom')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in bom: ",e))

  const inParts = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'parts')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in parts: ",e))

  const inAssemblies = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'assemblies')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in assemblies: ",e))


  //output to ym
  const bomToYm = state$.pluck("bom")
  const entityMetaToYm = state$.pluck("meta")
  const entityTransformsToYm = state$.pluck("transforms")
  const entitymeshesToYm = state$.pluck("meshes")
  const parts   = state$.pluck("types")
  const design  = state$.pluck('design')
  const authData= state$.pluck('authData')

  //simple query to determine if design already exists
  const queryDesignExists$ = combineLatestObj({design,authData})
    .map(data=>({data, query:'designExists'}))

  //saving should NOT take place before load is complete IFAND ONLY IF , we are reloading a design
  const saveDesigntoYm$ = state$
    .filter(state=>state.design.synched)//only try to save anything when the design is in "synch mode" aka has a ur
    .flatMap(_=>
      combineLatestObj({<commit_msg>chore(tweaks): minor tweaks to ym input/output  handling<commit_after>require("../../app.css")
import Rx from 'rx'
const {merge,just} = Rx.Observable
const of = Rx.Observable.of

//views & wrappers
import Settings from '../../components/widgets/Settings'
import FullScreenToggler from '../../components/widgets/FullScreenToggler/index'
import Help from '../../components/widgets/Help'

import {combineLatestObj} from '../../utils/obsUtils'

import {pick, equals} from 'ramda'

import {EntityInfosWrapper,BOMWrapper,GLWrapper,CommentsWrapper,progressBarWrapper} from '../../components/main/wrappers'

import intent from './intent'
import model  from './model'
import view   from './view'


import api from '../../api'

export default function main(sources) {
  const {DOM} = sources

  const actions = intent(sources)
  const state$  = model(undefined, actions, sources)

  //create visual elements
  const entityInfos = EntityInfosWrapper(state$,DOM)
  const comments    = CommentsWrapper(state$,DOM)
  const gl          = GLWrapper(state$, sources)
  const bom         = BOMWrapper(state$,DOM)
  const progressBar = progressBarWrapper(state$,DOM)

  const settingsC   = Settings({DOM, props$:state$})
  const fsToggler   = FullScreenToggler({DOM})
  const help        = Help({DOM, props$:state$})

  //outputs
  const vtree$  = view(state$, settingsC.DOM, fsToggler.DOM, bom.DOM,gl.DOM
    , entityInfos.DOM, comments.DOM, progressBar.DOM, help.DOM)
  const events$ = of( {gl:gl.events, entityInfos:entityInfos.events
    , bom:bom.events, comments:comments.events} )


  function postMsg(api$){
     return api$.map(data=>{
        const {request, response, requestName} = data
        return {target: request.source, message: response, targetOrigin:request.origin, requestName }
      })
  }

  const postMsg$ = postMsg( api( actions,state$ ) )

  //output to localStorage
  //in this case, settings
  const localStorage$ = state$
    .pluck("settings")
    .map( s=>({"jam!-settings":JSON.stringify(s)}) )


  //ym
  //this are responses from ym
  const designExists$ = sources.ym
    //.tap(e=>console.log("responses from ym",e))
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'designExists')
    .flatMap( data => data.catch(_=>just({error:true})) )//flag errors
    .filter(e=>!e.progress)//filter out progress data
    .map(data=> data.error ? false : true)//if we have an error return false, true otherwise
    //.forEach(e=>console.log("designExists: ",e))

  /*const inBom = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'bom')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in bom: ",e))

  const inParts = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'parts')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in parts: ",e))

  const inAssemblies = sources.ym
    .filter(res=>res.request.method==='get' && res.request.type === 'ymLoad' && res.request.typeDetail=== 'assemblies')
    .mergeAll()
    .pluck('response')
    .forEach(e=>console.log("in assemblies: ",e))*/


  //const designLoaded$ = combineLatestObj({inParts, inBom, inAssemblies})
  //  .startWith(true)

  //output to ym
  const bomToYm = state$.pluck("bom")
  const entityMetaToYm = state$.pluck("meta")
  const entityTransformsToYm = state$.pluck("transforms")
  const entitymeshesToYm = state$.pluck("meshes")
  const parts   = state$.pluck("types")
  const design  = state$.pluck('design')
  const authData= state$.pluck('authData')

  //simple query to determine if design already exists
  const queryDesignExists$ = combineLatestObj({design,authData})
    .filter(data=>data.authData.token !== undefined)
    .map(data=>({data, query:'designExists'}))

  //saving should NOT take place before load is complete IFAND ONLY IF , we are reloading a design
  const saveDesigntoYm$ = state$
    .filter(state=>state.design.synched)//only try to save anything when the design is in "synch mode" aka has a ur
    //skipUntil(designLoaded)
    .flatMap(_=>
      combineLatestObj({
{'fraction_non_alphanumeric': 0.159672091031445, 'fraction_numerical': 0.0, 'mean_word_length': 3.874180083482409, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 40, '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': '6860322', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2563, 'n_words': 624}