Open jayrbolton opened 7 years ago
Or at least replace the parentState
property with just the toggleBoxIDs$
stream:
toggleBox({
toggleBoxIDs$
, top: h('div', 'Click to toggle')
, bottom: h('div', 'This section is hidden by default')
})
Why pass in the entire parent state? How does the programmer recognize what stream the toggle box is actually using inside the parent's state?
also, line 9 - 11, instead of:
state.parentState.toggleBoxIDs$(
R.assoc(thisID, IDs[thisID] ? false : true, IDs)
)
you can do:
state.parentState.toggleBoxIDs$(R.assoc(thisID, !IDs[thisID], IDs))
!
will toggle a boolean
example how to manage things from the parent state with just open$
streams
function init() {
const boxes = {
openBox1$: flyd.stream(true)
, openBox2$: flyd.stream(false)
}
return {boxes}
}
function view(state) {
return h('div', [
toggleBox({open$: state.boxes.openBox1$, ...})
, toggleBox({open$: state.boxes.openBox2$, ...})
])
}
My suggestion is to eliminate the
thisID
and theparentState
properties in the parameter totoggleBox
and just pass in aopen$
stream, which makes the box open up when the stream contains a truthy value: