cycle组件化中的demo,为什么移动range时候没效果?
import xs from 'xstream';
import {run} from '@cycle/run';
import {div, input, p, makeDOMDriver} from '@cycle/dom';
import {html} from 'snabbdom-jsx';
function main(sources) {
const weightProps$ = xs.of({
label: 'Weight', unit: 'kg', min: 40, value: 70, max: 150
})
const heightProps$ = xs.of({
label: 'Height', unit: 'cm', min: 10, value: 170, max: 210
})
const weightSources = {
DOM: sources.DOM,
props: weightProps$
}
const heightSources = {
DOM: sources.DOM,
props: heightProps$
}
const weightSlider = LabeledSlider(weightSources)
const heightSlider = LabeledSlider(heightSources)
const weightDom$ = weightSlider.DOM
const weightValue$ = weightSlider.value
const heightVDom$ = heightSlider.DOM
const heightValue$ = heightSlider.value
const value$ = xs.combine(weightValue$, heightValue$)
.map( ([weight, height]) => {
const heightMeters = height * 0.01
const bmi = Math.round(weight / (heightMeters * heightMeters))
return bmi
})
const dom$ = xs.combine(value$, weightDom$, heightVDom$)
.map( ([bmi, weight, height]) => {
return <div>
{ weight }
{ height }
<h2>{ 'BMI is ' + bmi }</h2>
</div>
})
return {
DOM: dom$
}
}
function LabeledSlider(sources) {
const domSources = sources.DOM
const props$ = sources.props
const newValue$ = domSources
.select('.slider')
.events('input')
.map(ev => ev.target.value)
const state$ = props$
.map(
props => newValue$.map(val => ({
label: props.label,
unit: props.unit,
min: props.min,
value: val,
max: props.max
})).startWith(props)
)
.flatten()
.remember()
const vdom$ = state$.map( state => {
return <div class="labeled-slider">
<span class="label">{state.label + ' ' + state.value + state.unit}</span>
<input type="range" class="slider" min={state.min} max={state.max} value={state.value}/>
</div>
})
const sinks = {
DOM: vdom$,
value: state$.map(val => val.value),
}
return sinks
}
const drivers = {
DOM: makeDOMDriver('#app')
};
run(main, drivers);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
class => className
cycle和 react是一样的
而 vue则使用 class