Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const regl = require('regl')(reglOptions)
// note we keep the render function around, until we need to swap it out in case of new data
state.render = prepareRender(regl, state)
state.regl = regl
state.drawCommands.drawGrid = () => {}
state.drawCommands.drawCSGs = []
const sources$ = {
// data streams
params$: params$.filter(x => x !== undefined).multicast(), // we filter out pointless data from the get go
data$: data$.filter(x => x !== undefined), // we filter out pointless data from the get go
state$, // thanks to proxying, we also have access to the state observable/stream inside our actions
// inputs$: inputs$.filter(x => x !== undefined), // custom user inputs
// live ui elements only
gestures: state.useGestures ? require('most-gestures').pointerGestures(element) : {drags: most.never(), zooms: most.never(), taps: most.never()},
resizes$: state.useGestures ? require('./cameraAndControls/elementSizing')(element) : most.never(),
heartBeat$: require('./observable-utils/rafStream').rafStream() // state.useGestures ? require('./observable-utils/rafStream').rafStream() : most.never() // heartbeat provided by requestAnimationFrame
}
// create our action streams
const cameraControlsActions = makeCameraControlsActions(sources$)
const dataParamsActions = makeDataParamsActions(sources$)
const actions = most.mergeArray(dataParamsActions.concat(cameraControlsActions))
// combine proxy state & real state
attach(makeState(actions, state, regl))
// .startWith(state)
// skipRepeatsWith
// re-render whenever state changes, since visuals are a function of the state
state$.forEach(state => {
// console.log('sending data for render', state)
state.render(state)
.filter(event => event.data.type === 'params')
.map(function (event) {
try {
const {paramDefaults, paramValues, paramDefinitions} = event.data
return {paramDefaults, paramValues, paramDefinitions}
} catch (error) {
return {error}
}
}),
sources.store
.filter(data => data && data.design && data.design.parameters)
.map(data => data.design.parameters)
])
.map(data => ({type: 'setDesignParams', data}))
const timeOutDesignGeneration$ = most.never()
/* designPath$
sources.state$
.delay(60000) */
.map(data => ({type: 'timeOutDesignGeneration', data}))
.tap(x => console.log('timeOutDesignGeneration'))
// ui/toggles
const toggleAutoReload$ = most.mergeArray([
sources.dom.select('#autoReload').events('click')
.map(e => e.target.checked),
sources.store
.filter(data => data && data.autoReload !== undefined)
.map(data => data.autoReload)
])
.map(data => ({type: 'toggleAutoReload', data}))
.map(data => data.locale)
])
.map(data => ({type: 'changeLanguage', data}))
const toggleOptions$ = most.mergeArray([
sources.dom.select('#toggleOptions').events('click')
])
.map(data => ({type: 'toggleOptions', data}))
// non visual related actions
const setErrors$ = most.mergeArray([
sources.solidWorker.filter(event => 'error' in event)
])
.map(data => ({type: 'setErrors', data}))
const clearErrors$ = most.never() /* sources.state$
.filter(state => state.error !== undefined)
.map(state => state.error)
.skipRepeats()
.map(x => undefined)
.map(data => ({type: 'clearErrors', data}))
.delay(30000) */
// .forEach(x => console.log('clear errors', x))
const setAppUpdatesAvailable$ = most.mergeArray([
sources
.appUpdates
.map(data => ({type: 'setAppUpdatesAvailable', data})),
sources
.appUpdates
.delay(15000)// hide after 30 s
.map(data => ({type: 'setAppUpdatesAvailable', data: {available: false}}))
const regl = require('regl')(reglOptions)
// note we keep the render function around, until we need to swap it out in case of new data
state.render = prepareRender(regl, state)
state.regl = regl
state.drawCommands.drawGrid = () => {}
state.drawCommands.drawCSGs = []
const sources = {
// data streams
params$: params$.filter(x => x !== undefined).multicast(), // we filter out pointless data from the get go
data$: data$.filter(x => x !== undefined), // we filter out pointless data from the get go
state$, // thanks to proxying, we also have access to the state observable/stream inside our actions
// inputs$: inputs$.filter(x => x !== undefined), // custom user inputs
// live ui elements only
gestures: state.useGestures ? require('most-gestures').pointerGestures(element) : {drags: most.never(), zooms: most.never(), taps: most.never()},
resizes$: state.useGestures ? require('../../../utils/regl-renderer/src/controls/elementSizing')(element) : most.never(),
heartBeat$: require('../../../core/observable-utils/rafStream').rafStream() // state.useGestures ? require('./observable-utils/rafStream').rafStream() : most.never() // heartbeat provided by requestAnimationFrame
}
// create our action streams
const cameraControlsActions = makeCameraControlsActions(sources)
const dataParamsActions = makeDataParamsActions(sources)
const actions = most.mergeArray(dataParamsActions.concat(cameraControlsActions))
// combine proxy state & real state
attach(makeState(actions, state, regl))
// .startWith(state)
// skipRepeatsWith
// re-render whenever state changes, since visuals are a function of the state
state$
/*.skipRepeatsWith(function (state, previousState) {
function init() {
const list = Collection()
.setInstance('a', {foo: most.just(1).continueWith(() => most.just(4).delay(3)), bar: most.just(3).delay(2)})
.setInstance('b', {foo: most.just(2).continueWith(() => most.just(5).delay(10))});
const stream = snapshot(switchCollection(['foo', 'bar'], most.never().startWith(list)));
return run(stream);
}
completedTodoItemCount$,
todoItemCount$,
todoItems$: todoItemViews$,
},
)
const view$ = map(view, model$)
return {
view$,
addTodo$,
clearCompletedTodos$,
updateTodo$,
showActiveTodos$: never(),
showAllTodos$: never(),
showCompletedTodos$: never(),
removeTodo$,
}
}
export function sync (): SyncSubject {
return asSync(never());
}
function subject () {
const stream = multicast(never())
const observer = {
next: x => stream.source.event(scheduler.now(), x),
error: e => stream.source.error(scheduler.now(), e),
complete: x => stream.source.end(scheduler.now(), x)
}
return { observer, stream }
}