Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const wrapper = function WithLocalState(sources) {
const merger = createDefaultStateMerger()
// Combine the 2 channels into 1 stream with the merger
const state$ = xs
.combine(
sources[stateChannel].stream.startWith(undefined),
sources[localChannel].stream.startWith(undefined)
)
.map(([g, l]) => merger.merge(g, l))
.remember()
const sinks = cmp({
...omit([localChannel])(sources),
[stateChannel]: new StateSource(
state$.drop(2),
'withLocalState'
)
})
// Convert the emitted reducers back to state values and run
// it through extract
const updated$ = !sinks[stateChannel] ? xs.never() :
sinks[stateChannel]
.compose(sampleCombine(state$))
.map(([reducer, state]) => merger.extract(reducer(state)))
// Convert the extracted state values back to reducers for the separate
// channels
const global$ = updated$.map(extractedState => prevState => {
return { ...prevState, ...extractedState.global }